C Programming - Functions - Discussion
Discussion Forum : Functions - Point Out Errors (Q.No. 3)
3.
Point out the error in the program
#include<stdio.h>
int main()
{
int a=10;
void f();
a = f();
printf("%d\n", a);
return 0;
}
void f()
{
printf("Hi");
}
Answer: Option
Explanation:
The function void f() is not visible to the compiler while going through main() function. So we have to declare this prototype void f(); before to main() function. This kind of error will not occur in modern compilers.
Discussion:
14 comments Page 2 of 2.
Rajesh.T.K. said:
1 decade ago
Can anyone tell me about the function prototype?
Whether it should be declared only outside the main()?
Whether it should be declared only outside the main()?
Sumit said:
1 decade ago
f() is a void type function which does not return value so assignment is not allowed.
Vijay said:
1 decade ago
Wrong because the function f () is not returning anything?
Gauravj282 said:
1 decade ago
The variable 'a' is int type and after a=f() call f() which return hi to print but a is int type.
This reason is correct or not ? explain.
This reason is correct or not ? explain.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers