C questions in placement tests and university exams are rarely about syntax alone. Most of what you will find here is output prediction, pointer arithmetic, arrays and strings, structures and unions, storage classes, recursion, and file handling. The explanations walk through memory behaviour step by step, which is usually where the confusion sits rather than in the code itself.
Which statement is true about nested structures in C?
Answer: B
C allows structures to have other structures as members. This is called nested structures and is a common practice.
Q.2Hard
What happens if you assign a union member and then access another member? struct u { int a; char b; }; u.a = 257; printf("%d", u.b);
Answer: B
In a union, both members share memory. 257 in binary is 100000001. u.b (char) reads only the LSB, which is 1.
Q.3Hard
How can you initialize a structure array of 10 elements partially in C?
Answer: D
Both {0} and {} will initialize all members to zero. These are equivalent in C99 and later standards.
Q.4Hard
What is the difference between self-referential and recursive structures?
Answer: B
Self-referential structures contain pointers to the same structure type (like linked list nodes). Recursion refers to function calls, not structures.
Q.5Hard
Given union test { int x; char y[4]; }; If you set y[0]=65, y[1]=66, what happens to x?
Answer: C
Since union members share memory, setting y[0]=65 and y[1]=66 overwrites the int x value. The exact value depends on endianness.
Q.6Hard
Which approach is more memory efficient for storing 100 flags: array of char or bit fields in a structure?
Answer: B
Bit fields can pack 8 flags per byte, so 100 flags need ~13 bytes. Char array needs 100 bytes. Bit fields are more memory-efficient for flag storage.
Q.7Hard
In nested structures with pointers, which access method is correct? struct outer { struct inner *ptr; } *o; Accessing inner's member x:
Answer: D
Both o->ptr->x and (*o).ptr->x are equivalent. Arrow operator can chain for pointers, and (*pointer).member is equivalent to pointer->member.
Q.8Hard
What is the relationship between structure alignment and padding in modern C compilers?
Answer: B
Compilers add padding bytes between structure members to align them on boundaries (usually power of 2), improving memory access performance on the target architecture.
Q.9Hard
In a structure with flexible array members, which statement is INCORRECT? struct FlexArray { int len; int arr[]; };
Answer: B
Flexible array members require dynamic allocation; the structure itself cannot be allocated on the stack with a defined size for the array.
Q.10Hard
What is the output of the following? struct S { int a:3; int b:3; int c:3; }; printf("%zu", sizeof(struct S));
Answer: D
Bit field packing is implementation-defined. Size depends on compiler's bit field allocation strategy.
Q.11Hard
In competitive programming, when should you use union instead of struct?
Answer: B
Unions are optimal for memory-constrained scenarios and hardware programming where type casting is needed.
Q.12Hard
What will be the output of this code? struct X { int a; float b; }; struct Y { struct X x; int c; }; printf("%zu", sizeof(struct Y));
Answer: C
Nested struct X: int(4) + float(4) = 8 bytes. Y: struct X(8) + padding(0) + int(4) = 12, but with overall alignment it becomes 16 bytes.
Q.13Hard
In a structure, what does the #pragma pack(1) directive do?
Answer: A
#pragma pack(1) removes padding, making members occupy consecutive memory locations for compact storage.
Q.14Hard
If a structure contains a flexible array member, where must it be declared?
Answer: B
A flexible array member must be the last member of a structure. This is a C99 feature used for dynamic-sized arrays.
Q.15Hard
In competitive programming, when implementing a graph using adjacency lists, which data structure is most suitable?
Answer: B
An array of structures, where each structure contains a linked list (using self-referential pointers), is ideal for adjacency list representation.
Q.16Hard
If you have a structure with bit fields, which statement about their behavior is true?
Answer: A
Bit fields save memory by storing multiple values in single bytes, but behavior varies by compiler/platform, and you cannot take addresses of bit field members.
Q.17Hard
What is the output of this complex code? struct S { char c; int i; } s; printf("%lu", sizeof(s));
Answer: B
char(1 byte) + padding(3 bytes) + int(4 bytes) = 8 bytes due to alignment requirements.
Q.18Hard
In competitive programming, when you need a structure that can hold either an integer or a floating-point number (but not both simultaneously) in the most memory-efficient way, which should you use?
Answer: B
Union is memory-efficient as members share space. Only one can be accessed at a time, which suits the requirement.
Q.19Hard
What will be the output of the following code? union Test { int a; char b; }; union Test t; t.a = 65; printf("%d %c", t.a, t.b);
Answer: D
Since union members share memory, the output depends on the system's endianness. On little-endian systems, t.b would be 65 (or 'A'), but on big-endian systems, the result differs.
Q.20Hard
In competitive programming for GATE/ISRO 2025, which scenario would union be preferable over structure?
Answer: B
Unions are preferred when you have mutually exclusive data (only one member is used at a time) and memory is critical. A classic example is storing different data types in a tagged union pattern used in compilers and interpreters.