http://www.geeksforgeeks.org/g-fact-95/
1 in C, if a function is called before it is declared, then the compiler assumes that the return value of the function is of type int,
So the following code will not compile:
#include <stdio.h>int main (void) { // printf (" %d\n", Fun ()); return 0 Char fun () { return'G';}
Error: In fact, the fun function is defined two times, conflict
TEST1.C:9:6for"fun"char fun () ^ TEST1.C:5:implicit'fun' is here printf ("%d\n", Fun ()); ^
Changing the return value to an int row compiles and runs:
#include <stdio.h>int main (void) { printf ("%d\n" , Fun ()); return 0 int Fun () { returnten;}
2 in the C language, if the function is called before the declaration, what if the function's parameters are detected?
compiler assumes nothing about parameters. Therefore, the compiler'll not being able to perform compile-time checking of argument types and arity when the function is Applied to some arguments. This can cause problems.
The compiler does not make any assumptions about the parameters, so type checking cannot be done. The following code will be problematic, the output is garbage
int Main (void) { printf ("%d", sum (5 )); return 0 ;} int sum (intintint a) { return (a+b+c);}
Output Result:
[Email protected]:~/myprog/geeks4geeks/cpp$./A. out 1954607895[email protected]:~/myprog/geeks4geeks/cpp$./A. out 1943297623[email protected]:~/myprog/geeks4geeks/cpp$./A. out-16827881[email protected]:~/myprog/geeks4geeks/cpp$./A. out 67047927[email protected]:~/myprog/geeks4geeks/cpp$./A. out-354871129[email protected]:~/myprog/geeks4geeks/cpp$./A. out-562983177[email protected]:~/myprog/geeks4geeks/cpp$./A. out 33844135[email protected]:~/myprog/geeks4geeks/cpp$
So it's always recommended to declare a function before their use so that we don ' t see any surprises when the program is run (see this for more details).
C/cpp class Knowledge what happens when a function is called before it declaration in c? What happens when you use a function that is not declared in C