Govt Exams
In void functions, return statement (without value) can be used to exit the function prematurely. It's optional at the end since function exits automatically.
int fact(int n) { if(n
fact(4) = 4*fact(3) = 4*3*fact(2) = 4*3*2*fact(1) = 4*3*2*1 = 24. This is a proper factorial implementation with correct base case.
int add(int a, int b) { return a + b; }
int main() { printf("%d", add(5, add(3, 2))); return 0; }
Inner add(3,2) returns 5, then add(5,5) returns 10. Functions can be nested in arguments as long as return type matches parameter type.
If a non-void function doesn't explicitly return a value, it returns whatever garbage value happens to be in the return register, leading to undefined behavior.
The correct syntax is return_type function_name(parameters). Option A follows proper C syntax with int as return type, func as name, and void indicating no parameters.
Function prototypes inform the compiler about function name, return type, and parameters before the actual definition, enabling proper type checking during compilation.
Declaration (prototype) informs compiler about function signature; definition provides the actual implementation body.
Call by value passes a copy of the variable. Changes inside the function don't affect the original variable. Option B demonstrates this principle.
C requires function declaration before use (forward declaration or definition). Calling without prior declaration causes compilation error in modern C standards.
The void keyword is used as return type for functions that do not return any value.