Govt. Exams
Entrance Exams
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.
The static keyword restricts function scope to the file in which it is declared, preventing external linkage.
A base case is essential in recursive functions to provide a termination condition, otherwise the function will recurse infinitely.
int func(int *p) { return *p; }
int main() { int x = 10; printf("%d", func(&x)); }
The function receives a pointer to x, dereferences it with *p, and returns the value 10.