Padding adds unused bytes between members to align them on word boundaries, improving CPU access efficiency and performance.
Q.602Easy
How do you access a structure member through a pointer in C?
Answer: B
The arrow operator (->) is used to access structure members through a pointer. It dereferences the pointer and accesses the member in one operation.
Q.603Medium
Consider struct test { int x; double y; char z; }; What is the minimum size of this structure (assuming 4-byte int, 8-byte double)?
Answer: D
Due to padding: int (4) + padding (4) + double (8) + char (1) + padding (3) = 24 bytes. The structure aligns to the largest member size.
Q.604Medium
What will be printed by this code? struct s { int a; struct s *next; }; struct s *ptr; sizeof(struct s)
Answer: C
sizeof(int) = 4 bytes, sizeof(pointer) = 8 bytes (on 64-bit systems). Total = 12 bytes. Pointers are fixed size regardless of what they point to.
Q.605Medium
In a nested structure, how do you access the innermost member? struct outer { struct inner { int value; } in; } obj;
Answer: B
For nested structures accessed through an object, use the dot operator multiple times: obj.in.value accesses the value member of the inner structure.
Advertisement
Q.606Easy
What is the primary advantage of using structures in C?
Answer: B
Structures allow you to combine multiple data types into a single composite type, making code organization and data management more efficient.
Q.607Medium
Which of the following correctly initializes a structure array? struct point { int x, y; } arr[3] = ?
Answer: A
Structure arrays are initialized with nested braces, where each set of braces contains initialization values for one structure element.
Q.608Medium
What happens when you modify a union member that overlaps with another?
Answer: C
Since union members share memory, modifying one member overwrites the value of other members because they occupy the same memory location.
Q.609Medium
Which statement is correct about bit fields in structures?
Answer: B
Bit fields allow you to specify the number of bits for integral members, enabling memory optimization by packing multiple small values into a single byte.
Q.610Medium
What is the difference between struct tag and struct type in C?
Answer: B
In 'struct person { int age; } p;', 'person' is the tag (structure name) and 'p' is the type/variable. Tag names the structure template; type creates actual instances.
Q.611Hard
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.612Medium
What will be the behavior of this code? struct s { int a; }; struct s obj = {5}; struct s *ptr = &obj; ptr->a = 10; printf("%d", obj.a);
Answer: B
ptr points to obj, so ptr->a = 10 modifies obj.a to 10. The printf outputs the modified value 10.
Q.613Hard
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.614Hard
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.615Medium
Which initialization method for structures is used in designated initializers (C99 feature)?
Answer: B
Designated initializers (C99) allow specifying members by name using dot notation, making code more readable and maintainable.
Q.616Easy
What is the output of the following code?
struct Point { int x; int y; };
struct Point p = {5};
printf("%d %d", p.x, p.y);
Answer: A
When initializing a struct with fewer values than members, remaining members are zero-initialized. p.x=5, p.y=0.
Q.617Medium
How much memory (in bytes) will the following structure occupy on a 32-bit system?
struct Data { char c; int i; short s; };
Answer: C
Due to padding/alignment: char(1) + padding(3) + int(4) + short(2) = 12 bytes on 32-bit systems.
Q.618Easy
Which of the following is true about typedef struct?
Answer: A
typedef creates an alias for the struct type, allowing direct use without 'struct' keyword.
Q.619Medium
What is the primary difference between passing a structure by value vs by pointer in function calls?
Answer: C
Passing by pointer avoids copying the entire structure, making it efficient for large data structures.
Q.620Easy
Consider union u { int i; char c; float f; }; What is the size of this union?
Answer: A
Union size equals the largest member size. float is typically 4 bytes, which is largest.