What will happen if a value is returned from a function declared with void return type in C ?
Tripura Public Service Commission - 2026,
Answer: C
The keyed result is a compilation error.
A function declared void promises to return no value. The C standard makes a return statement with an expression in a void function a constraint violation, so the compiler must issue a diagnostic, and C++ compilers and strict C compilers reject it outright.
The value is not printed automatically, since returning a value never prints anything. The problem is caught when the program is compiled, not when it runs, so 'runtime error' is wrong; and the compiler does not silently ignore it.
Please log in or register to report this question.