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.
Q.2Hard
Which of the following correctly demonstrates pointer arithmetic?
Answer: A
Option A shows pointer arithmetic where p++ increments the pointer by the size of int (4 bytes). Other options are regular arithmetic operations.
Q.3Hard
What is the output of the following code?
int a = 5;
int *p = &a;
int q = &p;
printf("%d", q);
Answer: A
q is a pointer to pointer p. **q dereferences both pointers, giving the value of a, which is 5.
Q.4Hard
What is true about the variable declared as 'extern int count;' inside a function?
Answer: B
extern is a declaration (not definition) that tells compiler the variable exists elsewhere in program. It provides global scope.
Q.5Hard
Consider a structure with int (4 bytes), char (1 byte), and double (8 bytes). What is the minimum size due to alignment requirements?
Answer: C
Due to structure padding/alignment, the size becomes 24 bytes (8-byte alignment for double). Members are padded to maintain alignment.
Advertisement
Q.6Hard
Which of the following statements about type qualifiers is INCORRECT?
Answer: C
restrict prevents pointer aliasing (not allows). It tells compiler that pointer is the only way to access that object.
Q.7Hard
In the declaration 'volatile int x;', what does volatile signify?
Answer: A
volatile tells the compiler that the variable's value may change unexpectedly (e.g., by hardware, signals, or another thread), so the compiler should not optimize it.
Q.8Hard
In the declaration 'int *p, q;', what are the data types?
Answer: B
The '*' applies only to the immediately following variable. So 'int *p' declares p as pointer to int, and 'q' is just an int.
Q.9Hard
What is the purpose of the 'restrict' keyword in modern C?
Answer: B
restrict (C99) informs the compiler that a pointer is the sole accessor to the object, enabling optimization. It doesn't prevent modification.
Q.10Hard
What is the difference between 'const int *p' and 'int * const p'?
Answer: C
'const int *p' - pointer can change but value cannot. 'int * const p' - value can change but pointer cannot.
Q.11Hard
What is printed by: int x = 5; printf("%d %d", x++, ++x);?
Answer: C
Modifying variable x twice without intervening sequence point causes undefined behavior.
Q.12Hard
Which of the following correctly declares a constant pointer to a constant integer?
Answer: D
Both 'const int * const p' and 'int const * const p' are equivalent and declare constant pointer to constant integer.
Q.13Hard
Which of the following statements about 'register' keyword is TRUE?
Answer: D
Register is a hint only; compiler may ignore it. You cannot use & operator on register variables.
Q.14Hard
What is the primary purpose of the 'restrict' keyword introduced in C99?
Answer: B
The 'restrict' qualifier tells the compiler that a pointer is the only way to access that object, enabling optimizations.
Q.15Hard
What happens in this code: int arr[5]; int *p = &arr[0]; printf("%d", sizeof(p));
Answer: B
p is a pointer variable, so sizeof(p) returns the size of the pointer itself (4 bytes on 32-bit, 8 bytes on 64-bit systems), not the array.
Q.16Hard
What will be the result of the following expression:
float x = 0.1 + 0.2;
if(x == 0.3) printf("Equal"); else printf("Not Equal");
Answer: B
Due to floating-point precision limitations, 0.1 + 0.2 does not exactly equal 0.3 in binary representation. Direct comparison with == fails.
Q.17Hard
What happens when a volatile variable is declared in a multi-threaded C program?
Answer: B
volatile tells compiler not to optimize variable accesses and to fetch fresh value from memory, useful for hardware registers and shared memory, but doesn't guarantee thread-safety without synchronization.