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");
}
Error: Not allowed assignment
Error: Doesn't print anything
No error
None of above
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.

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?

Suman said:   1 decade ago
@Rajesh.

It should be before your calling function.

Anomie said:   3 years ago
Can anyone help me to clear this in detail?


Post your comments here:

Your comments will be displayed after verification.