A C99 program's main reaches the closing brace without a return statement. What exit status does the process report?
Correct answer
A. 0, because reaching the end of main is equivalent to returning zero
22 views
A. 0, because reaching the end of main is equivalent to returning zero
22 views
In C99 and later, flowing off the end of main is equivalent to executing return 0, so the process reports success to the operating system. This applies only to main: any other non-void function that falls off the end has undefined behaviour once its value is used. Using the returned value of exit status is separate from main's implicit zero, since exit takes an explicit argument.
Asked in: NTS, PPSC IT, Campus Interviews
Not sure why the answer is A? Ask here and get an explanation.