Which return statement is legal inside a function declared as void f(void)?
Correct answer
C. return;
14 views
C. return;
14 views
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.
Asked in: NTS, PPSC IT, Campus Interviews
Not sure why the answer is C? Ask here and get an explanation.