Google Search

Friday, June 10, 2016

Who calls the main() function in C/C++?

a. You need either a definition or a prototype in order to properly call a function, but "main" must never be called from any other function, so it must not be declared.
b. Because the C standard says so. Operating systems pass the return value to the calling program (usually the shell). Some compilers will accept void main, but this is a non-standard extension (it usually means "always return zero to the OS")
c. By convention, a non-zero return value signals that an error occurred. Shell scripts and other programs can use this to find out if your program terminated successfully.

No comments:

Post a Comment