Analyze this code:
for(int i = 0; i < 5; i++) {
if(i == 2) continue;
if(i == 3) break;
printf("%d ", i);
}
What is the output?
Answer: A
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'.
Q.282Medium
Which of the following statements about the switch-case construct is INCORRECT?
Answer: A
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.
Q.283Hard
Consider the code:
int sum = 0;
for(int i = 1; i <= 10; i++) {
if(i % 2 == 0) continue;
sum += i;
}
printf("%d", sum);
What will be printed?
Answer: A
The loop adds only odd numbers (1,3,5,7,9) due to the continue statement when i is even. Sum = 1+3+5+7+9 = 25.
Q.284Easy
What is the primary purpose of using functions in C programming?
Answer: A
Functions allow code reusability, modularity, and easier maintenance. They break down complex problems into smaller, manageable pieces.
Q.285Easy
Which keyword is used to define a function in C?
Answer: C
In C, functions are defined by specifying the return type followed by the function name and parameters. No specific 'function' keyword is used.
Advertisement
Q.286Medium
What is the default return type of a function in C if not specified?
Answer: B
In older C standards (before C99), if no return type is specified, the default is 'int'. However, this is deprecated in modern C standards.
Q.287Easy
Which of the following is a correct function declaration?
Answer: A
Function declaration syntax is: return_type function_name(parameter_list);
Q.288Easy
What will be the output of the following code?
int func(int x) { return x * 2; }
int main() { printf("%d", func(5)); }
Answer: B
func(5) returns 5 * 2 = 10, which is then printed.
Q.289Easy
How many times can a function be called in a C program?
Answer: C
A function can be called as many times as needed within a program, limited only by memory and stack constraints.
Q.290Medium
What is the difference between function declaration and function definition?
Answer: A
Declaration (prototype) tells the compiler about the function signature; definition provides the actual function body and implementation.
Q.291Medium
What happens if a function does not have a return statement?
Answer: C
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.
Q.292Medium
Which of the following function calls is valid?
int calculate(int a, float b, char c);
Answer: A
All three parameters must be provided in correct order and compatible types.
Q.293Medium
What is a recursive function?
Answer: A
A recursive function is one that calls itself. It must have a base case to avoid infinite recursion.
Q.294Medium
What is the issue with the following code?
int factorial(int n) { return n * factorial(n-1); }
Answer: B
The recursive function lacks a base case (like if n==0 return 1) to terminate recursion, causing infinite recursion and stack overflow.
Q.295Medium
In C, are function parameters passed by value or by reference by default?
Answer: A
C passes parameters by value by default. To achieve pass-by-reference effect, pointers must be used explicitly.
Q.296Medium
What will be the output?
void modify(int x) { x = x + 10; }
int main() { int a = 5; modify(a); printf("%d", a); }
Answer: A
Since parameters are passed by value, changes to 'x' inside modify() don't affect 'a' in main(). Output is 5.
Q.297Hard
How can you modify a variable inside a function and reflect the change in the calling function?
Answer: D
All three methods work: return value, pass pointers, or use global variables. Each has different use cases and implications.
Q.298Hard
What is the output of this code?
int* getPointer(int *p) { return p; }
int main() { int a = 10; int *ptr = getPointer(&a); printf("%d", *ptr); }
Answer: A
The function receives the address of 'a', returns it, and dereferencing gives 10. However, returning pointers to local variables is risky in other contexts.
Q.299Hard
What are static local variables in functions used for?
Answer: A
Static local variables retain their value between function calls, initialized only once, and are stored in data segment.
Q.300Hard
What will be the output?
int counter() { static int count = 0; return ++count; }
int main() { printf("%d ", counter()); printf("%d ", counter()); printf("%d", counter()); }
Answer: B
Static variable 'count' retains its value. First call: 0+1=1, second: 1+1=2, third: 2+1=3.