What will be the output of: int x = 10; printf("%d %d", x, x++);
Answer: D
Modifying and using a variable in the same expression without an intervening sequence point results in undefined behavior.
Q.2Hard
Consider the expression: int arr[5]; What does arr represent without the index?
Answer: B
In C, the array name arr (without index) decays to a pointer to its first element, representing the base address.
Q.3Hard
Which storage class has a default value of 0 if not explicitly initialized?
Answer: C
Static variables are initialized to 0 by default. auto and register variables have garbage values if not initialized. extern variables are declared elsewhere.
Q.4Hard
What will be the output of the following code?
#include <stdio.h>
int main() {
int x = 5;
printf("%d", ++x + x++);
return 0;
}
Answer: D
The expression ++x + x++ involves modifying x multiple times without an intervening sequence point, leading to undefined behavior in C.
Q.5Hard
What is the main difference between #define and const in C?
Answer: C
#define is a preprocessor directive replaced before compilation, while const creates an actual variable. const occupies memory; #define does not.
Advertisement
Q.6Hard
Which of the following correctly declares a function pointer?
Answer: B
Function pointers require parentheses around the pointer name: int (*func)(). Option D declares a function returning int pointer, not a function pointer.
Q.7Hard
What will be the output of the following code?
#include <stdio.h>
int main() {
int x = 5;
int y = ++x * ++x;
printf("%d", y);
return 0;
}
Answer: C
The expression ++x * ++x modifies x twice without an intervening sequence point, causing undefined behavior.
Q.8Hard
Consider a function declared as 'static int func()'. What is the scope of this function?
Answer: B
When 'static' is applied to a function at file scope, it restricts the function's visibility to that translation unit (file) only.
Q.9Hard
What is the output of: printf("%d", (int)3.7);?
Answer: B
Type casting (int)3.7 truncates the decimal part, converting 3.7 to 3. The fractional part is discarded.
Q.10Hard
Which of the following best describes the 'register' storage class in modern C compilers?
Answer: B
The 'register' keyword is a hint for compiler optimization. Modern compilers often ignore it as they have sophisticated optimization strategies.
Q.11Hard
What will be the output of: int x = 5; printf("%d", x++ + ++x);
Answer: D
This exhibits undefined behavior due to multiple modifications of the same variable 'x' without intervening sequence points.
Q.12Hard
What is the result of: int x = 10; int y = x++ + x++;
Answer: D
Multiple post-increments without sequence points lead to undefined behavior.
Q.13Hard
What is the output of: int x = 5; int y = ++x + x++;
Answer: C
This involves undefined behavior due to modification of x multiple times without intervening sequence points.
Q.14Hard
What is the scope of a variable declared inside a block with 'static'?
Answer: C
A static variable declared in a block has block scope but static storage duration, persisting between function calls.
Q.15Hard
What will be the output of: int a = 1; int b = 2; a = a + b; b = a - b; a = a - b; printf("%d %d", a, b);
Answer: B
Initial: a=1, b=2. After step 1: a=3, b=2. After step 2: a=3, b=1. After step 3: a=2, b=1. Output is '2 1'.
Q.16Hard
Which of the following about function pointers in C is correct?
Answer: B
int (*func)(); declares a pointer to a function that returns int. Option A declares a function returning pointer to int.
Q.17Hard
What is the output of: float x = 25; printf("%f", x);
Answer: B
25 is integer division (not float division), so result is 2 (integer), then converted to 2.0 (float).
Q.18Hard
Which of the following correctly uses memcpy()?
Answer: D
memcpy(dest, src, count) copies 'count' bytes from src to dest. strlen() and sizeof() may not give correct results for all data types.
Q.19Hard
Consider the following declaration:
int (*func_ptr)(int, int, int);
Which of the following function signatures can be correctly assigned to func_ptr?
Answer: A
func_ptr must point to a function that takes exactly 3 int parameters and returns int. Only option A matches this signature exactly.
Q.20Hard
What will be the size of the following structure?
struct test {
char c;
int i;
float f;
};
Answer: D
Size depends on compiler's padding and alignment rules. Typically 12 bytes with padding, but varies by system.