As far as I know, return
statement in void function will throw an error.
But in the below program that is not the case.
Here the displayed output
The code you've presented is actually invalid in C99 for a variety of reasons, but the most painful one is below:
foo.c:5:17: warning: implicit declaration of function 'fun' is invalid in C99 [-Wimplicit-function-declaration]
printf("%d",fun(fun(fun(i))));
^
foo.c:8:6: error: conflicting types for 'fun'
void fun(int i)
^
foo.c:5:17: note: previous implicit declaration is here
printf("%d",fun(fun(fun(i))));
^
Note that if you gave a function prototype for fun()
, which you really should, then you would get a different set of errors:
foo.c:7:25: error: passing 'void' to parameter of incompatible type 'int'
printf("%d",fun(fun(fun(i))));
^~~~~~