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 2 of 4.
Rohan said:
9 years ago
extern int fun(float).
In this statement "extern" also there. So that's means the memory of this function allocated in some other program. So this is one of the error.
In this statement "extern" also there. So that's means the memory of this function allocated in some other program. So this is one of the error.
(1)
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)
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.
Nishanth said:
1 decade ago
@Neha.
After increment we get 4.14.
But when it return it will be type casted to int so 4 will get stored in a.
After increment we get 4.14.
But when it return it will be type casted to int so 4 will get stored in a.
Amlan Karmakar said:
1 decade ago
@Suman.
(int)++a means that float value of aa is type casted to int. It is called explicit conversion.
(int)++a means that float value of aa is type casted to int. It is called explicit conversion.
Pooja said:
10 years ago
Error: Previous declaration of 'fun' was here.
Can anybody explain me the meaning of the above error?
Can anybody explain me the meaning of the above error?
Sundar said:
1 decade ago
A small correction required.
int fun(int aa) --> int fun(floatt aa)
It will display 4 as output.
int fun(int aa) --> int fun(floatt aa)
It will display 4 as output.
Sushma said:
1 decade ago
What is actually "1. type mismatch in redeclaration of function" in this question?
Ssindham said:
9 years ago
Great discussion.
Thanks @Suman, Amlan Karmakar, @Neha, @Rekha @Nishanth.
Thanks @Suman, Amlan Karmakar, @Neha, @Rekha @Nishanth.
Trisha said:
1 decade ago
What is that 2nd error? I didn't get that point. Can you please explain?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers