1. Home
  2. Computer Science MCQs
  3. C Programming
  4. A C99 program's main reaches the closing brace without a…

Added 30 Nov -0001

A C99 program's main reaches the closing brace without a return statement. What exit status does the process report?

  1. 0, because reaching the end of main is equivalent to returning zero Correct answer
  2. An indeterminate value, because no return expression was ever evaluated
  3. 1, because falling off the end of main is treated as abnormal termination
  4. The value is implementation-defined and must be read from the shell

Correct answer

A. 0, because reaching the end of main is equivalent to returning zero

23 views

MCQSEXAM

Explanation

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.

Reference

Asked in: NTS, PPSC IT, Campus Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is A? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More C Programming MCQs

Practise all C Programming MCQs

Similar MCQs