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.
Q.302Medium
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.303Medium
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.304Medium
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.305Medium
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.
Advertisement
Q.306Medium
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.307Medium
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.308Medium
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.309Medium
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.310Medium
What will be the output of this code?
union Data { int x; char y; };
Data d = {65};
d.y = 'A';
printf("%d", d.x);
Answer: D
Modifying y changes the same memory location as x. Only the last byte of x is affected, leading to unpredictable output.
Q.311Medium
What is the issue with bit fields in structures regarding portability?
Answer: A
Bit field allocation order (left-to-right or right-to-left) varies across compilers, affecting portability.
Q.312Medium
What happens when you access a union member that wasn't the last one to be written?
Answer: C
All union members share the same memory. Accessing a member not recently written gives bitwise interpretation of that memory.
Q.313Medium
When comparing nested structures, which access method is INVALID?
struct Address { char city[20]; };
struct Person { Address addr; };
Person p;
Answer: C
p is a structure variable (not pointer), so arrow operator (->) cannot be used. Only dot operator works.
Q.314Medium
Which structure feature is most suitable for implementing a state machine with limited states?
Answer: A
Bit fields efficiently store boolean/limited-range states using minimal memory, ideal for state machines.
Q.315Medium
What is the primary use case for unions in embedded systems?
Answer: A
Unions enable type punning and efficient hardware register representation where different interpretations of same memory are needed.
Q.316Medium
What is the size of the following structure on a 32-bit system?
struct Point { char c; int x; };
Answer: B
Due to structure padding/alignment, char (1 byte) + 3 bytes padding + int (4 bytes) = 8 bytes total.
Q.317Medium
Which feature of structures makes them suitable for implementing linked lists?
Answer: A
Self-referential pointers (a structure containing a pointer to itself) are essential for creating linked list nodes.
Q.318Medium
What happens if you attempt to assign one structure variable to another of the same type?
Answer: B
In C, you can assign one structure variable to another of the same type, and all members are copied (shallow copy).
Q.319Medium
Which of the following is a valid declaration of nested structure?
Answer: C
Both nested structure definitions (defining B inside A and declaring B as member) are valid in C.
Q.320Medium
What is the primary advantage of using unions in embedded systems?
Answer: A
Unions are primarily used in embedded systems to conserve memory by allowing multiple members to share the same memory location.