C Programming - Declarations and Initializations - Discussion
Discussion Forum : Declarations and Initializations - Find Output of Program (Q.No. 8)
8.
What is the output of the program
#include<stdio.h>
int main()
{
extern int fun(float);
int a;
a = fun(3.14);
printf("%d\n", a);
return 0;
}
int fun(int aa)
{
return (int)++aa;
}
Answer: Option
Explanation:
2 Errors
1. Type mismatch in redeclaration of fun
2. Type mismatch in parameter aa
1. Type mismatch in redeclaration of fun
2. Type mismatch in parameter aa
Discussion:
35 comments Page 1 of 4.
Chinnu said:
2 months ago
@All.
Though the extern statement was called in the program, as Rohan said, the memory of the function is assigned in some other program, but still we are not using any scope of it in the current program, which would not create an error.
The error is due to in function definition argument passed was an int, but it should be a float and the function was defined inside the main function; it should be defined out of it.
Though the extern statement was called in the program, as Rohan said, the memory of the function is assigned in some other program, but still we are not using any scope of it in the current program, which would not create an error.
The error is due to in function definition argument passed was an int, but it should be a float and the function was defined inside the main function; it should be defined out of it.
Ravi said:
3 years ago
@Lakshmi.
Yes, you are correct it can be ++a;.
Yes, you are correct it can be ++a;.
Chandana said:
7 years ago
Output should be linker error isn't it? Because function declared as extern is taken care of linker not by the compiler.
Lakshmi said:
7 years ago
Why ++aa?
It can be ++a.
It can be ++a.
(1)
Parth said:
8 years ago
Had the data type of the argument in function definition of function 'fun' been correct, I guess the program still should not run because the function 'fun' has been declared inside the main function. So, technically it's scope is inside only the main function. So why, would the function be called? Can someone clear my doubt?
Udhaya said:
8 years ago
#include<stdio.h>
int main()
{
extern int fun(float);
float a;
a = fun(3.14);
printf("%d\n", a);
return 0;
}
int fun(float a)
{
return (int)++a;
}
This give output '0'.
int main()
{
extern int fun(float);
float a;
a = fun(3.14);
printf("%d\n", a);
return 0;
}
int fun(float a)
{
return (int)++a;
}
This give output '0'.
(4)
Suraj said:
8 years ago
After passing the argument to the function need its type of float than in the function it increment the value of a then you get the answer 4.
(1)
Dnyanu said:
9 years ago
Thank you all for the explanation.
(1)
Ssindham said:
9 years ago
Great discussion.
Thanks @Suman, Amlan Karmakar, @Neha, @Rekha @Nishanth.
Thanks @Suman, Amlan Karmakar, @Neha, @Rekha @Nishanth.
Panu said:
9 years ago
How two functions are mismatch?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers