Govt Exams
void modify(int x) { x = x + 10; }
int main() { int a = 5; modify(a); printf("%d", a); }
Since parameters are passed by value, changes to 'x' inside modify() don't affect 'a' in main(). Output is 5.
C passes parameters by value by default. To achieve pass-by-reference effect, pointers must be used explicitly.
int factorial(int n) { return n * factorial(n-1); }
The recursive function lacks a base case (like if n==0 return 1) to terminate recursion, causing infinite recursion and stack overflow.
A recursive function is one that calls itself. It must have a base case to avoid infinite recursion.
int calculate(int a, float b, char c);
All three parameters must be provided in correct order and compatible types.
If a function with a non-void return type lacks a return statement, it returns undefined/garbage value. For void functions, no return is needed.
Declaration (prototype) tells the compiler about the function signature; definition provides the actual function body and implementation.
In older C standards (before C99), if no return type is specified, the default is 'int'. However, this is deprecated in modern C standards.
The default case is optional in a switch statement. It executes when no case matches, but it is not mandatory. All other statements are correct properties of switch-case.
for(int i = 0; i < 5; i++) {
if(i == 2) continue;
if(i == 3) break;
printf("%d ", i);
}
What is the output?
When i=0: prints 0. When i=1: prints 1. When i=2: continue skips printf. When i=3: break terminates the loop. Output is '0 1'.