Can main() function return double?
Yes. According to C standard, main() should return a int
value. But not must.
From C99
5.1.2.2.3 Program termination If the return type of the main function is a type compatible with int, a return from the initial call to the main function is equivalent to calling the exit function with the value returned by the main function as its argument;10) reaching the } that terminates the main function returns a value of 0. If the return type is not compatible with int, the termination status returned to the host environment is unspecified
Reference here - 5.1.2.2.3 Program termination http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1256.pdf
I don't know what it would mean if main
returned double. Anyway here is what happens with gcc:
double main (){ return 0.0;}
$ cc double.cdouble.c: In function 'main':double.c:2: warning: return type of 'main' is not 'int'$ ./a.out$ echo $?255$