1. Home
  2. Computer Science MCQs
  3. C Programming
  4. Which return statement is legal inside a function declared…

Added 30 Nov -0001

Which return statement is legal inside a function declared as void f(void)?

  1. return (void)0;
  2. return NULL;
  3. return; Correct answer
  4. return 0;

Correct answer

C. return;

14 views

MCQSEXAM

Explanation

Void functions may use a bare return; to leave early, but a return with any expression is a constraint violation because the standard forbids an expression in a void function. Even return (void)0; is not permitted in C, although C++ accepts an expression of type void there. A function that must report failure should return int or an error code instead.

Reference

Asked in: NTS, PPSC IT, Campus Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is C? 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