Govt. Exams
Entrance Exams
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'.
The break statement only exits the innermost loop that contains it. It does not affect the outer loop's execution. The outer loop will continue its iterations normally.
Only the break statement whose associated if condition evaluates to true will be executed, exiting the loop immediately.