Structures in C Programming MCQ Questions and Answers

1. Consider:
struct S { int a; char b; double c; };
What is the most likely value of sizeof(struct S) under the stated assumptions?
A) 13
B) 16
C) 24
D) 32
Answer: C

2. Which of the following is not a valid way to initialize a structure struct P { int x; int y; }; at declaration?
A) struct P p = { .x = 1, .y = 2 };
B) struct P p = {1, 2};
C) struct P p = {.x = 1};
D) struct P p = (struct P){.x = 1, .y = 2, .z = 3};
Answer: D

3. Given:
struct Node {
int data;
struct Node *next;
};
Which statement is true?
A) struct Node is an incomplete type because it contains a pointer to itself.
B) The declaration is invalid because a struct cannot contain a member of its own type.
C) The struct is incomplete until next is assigned.
D) The declaration is valid; a struct may contain a pointer to the same struct type.
Answer: D

4. Which of the following best describes the behavior of assigning one struct to another (e.g., a = b;) in C?
A) Memberwise copy of all members.
B) Bitwise copy only for POD structs; fails for pointers.
C) Shallow copy that copies only pointer addresses but not pointed data.
D) A and C are both correct (memberwise and shallow for pointers).
Answer: D

5. Consider:
struct A { char x; };
struct B { char x; char y; };
Which statement is true about sizeof(struct A) and sizeof(struct B)?
A) sizeof(A) must be 1 and sizeof(B) must be 2 on all platforms.
B) sizeof(A) is 1; sizeof(B) is at least 2 but may be larger due to alignment.
C) sizeof(A) and sizeof(B) are implementation-defined and may be equal.
D) sizeof(A) is 8 and sizeof(B) is 16 because of struct overhead.
Answer: B

6. Which of these is a valid forward declaration for use in mutually recursive structs?
A) struct A; struct B { struct A a; }; struct A { struct B b; };
B) struct A; struct B { struct A *a; }; struct A { struct B b; };
C) struct A { struct B *b; }; struct B { struct A *a; };
D) Both B and C are valid patterns for mutual recursion.
Answer: D

7. In C99, which feature allows defining a struct member whose size is determined at runtime (flexible array member)?
A) Using int arr[]; as the last member.
B) Declaring pointer and allocating separately.
C) Using variable-length arrays inside the struct.
D) Using #define FLEXIBLE pragma.
Answer: A

8. Which statement about bit-fields in structures is FALSE?
A) Bit-fields may be declared with type int, unsigned int, or signed int.
B) The order and packing of bit-fields is implementation-defined.
C) You can take the address of a bit-field.
D) Bit-fields may be used for memory-compact flag storage.
Answer: C

9. Given:
typedef struct { int x; int y; } Point;
Which of the following is valid?
A) Point p = {1,2};
B) struct Point p = {1,2};
C) Both A and B.
D) Neither A nor B.
Answer: A

10. What does offsetof(struct S, m) compute?
A) The size of member m inside struct S.
B) The offset in bytes of member m from the start of struct S.
C) The alignment requirement of member m.
D) The pointer to member m.
Answer: B

11. Which of the following is true about anonymous structs/unions (C11 feature) used as members?
A) They allow members to be accessed directly as if they were in the containing struct.
B) They are not allowed to contain named members.
C) They require a tag name to be accessed.
D) They change the address of the containing struct.
Answer: A

12. Consider passing a struct S to a function by value vs by pointer. Which is generally true?
A) Passing by value always faster than pointer.
B) Passing by pointer avoids copying the whole struct and is often more efficient for large structs.
C) Passing by value allows the callee to modify the caller’s struct.
D) Passing by pointer copies the struct automatically.
Answer: B

13. Which of the following correctly declares a pointer to a function that takes a struct by pointer and returns void?
A) void (*f)(struct S*);
B) void *f(struct S*);
C) void f(struct S*);
D) void (*f)(struct S);
Answer: A

14. If a struct contains double and char, how can you minimize padding?
A) Put char first then double.
B) Put double first then char.
C) Use bit-fields for double.
D) Padding cannot be changed by ordering.
Answer: B

15. Consider:
struct A { int i:5; int j:27; };
Which is true about sizeof(struct A) on a typical system where sizeof(int)==4 and int has 32 bits?
A) sizeof(A) is 4 bytes.
B) sizeof(A) is 8 bytes.
C) sizeof(A) is 5 bytes.
D) Implementation-defined; most compilers will give 4 bytes.
Answer: D

16. Which is true about typedef and struct?
A) typedef struct S S; creates a new type alias named S for struct S.
B) typedef cannot be used with structs.
C) typedef struct S { … } S; declares and defines without alias.
D) typedef makes a struct automatically a pointer type.
Answer: A

17. Which of the following about copying structs with pointers inside is correct?
A) A direct assignment copies pointer values, not the memory they point to.
B) A direct assignment creates deep copies of the pointed data.
C) The C standard guarantees deep copy semantics for pointer members.
D) Struct copy will cause double-free on free() of either copy automatically.
Answer: A

18. Consider:
struct S { int x; };
struct S func(void) { struct S t = {5}; return t; }
What happens when func() returns t?
A) Return of struct by value copies the struct to the caller (may use RVO/optimization).
B) Undefined behavior because local t goes out of scope.
C) Caller receives a dangling pointer.
D) t must be allocated with malloc for this to work.
Answer: A

19. Which of the following is an invalid struct member declaration?
A) int a[0]; inside a struct (GCC extension).
B) int a[]; as the last member (flexible array member in C99).
C) struct S a; where S is the same struct tag (not via pointer).
D) int (*f)(int); a function pointer.
Answer: C

20. What does the C standard say about the relative order of members in memory?
A) Members are stored in some unspecified order for optimization.
B) The order of members in memory is the same as they are declared, possibly with padding in between.
C) Members are always tightly packed without padding.
D) The compiler may reorder members to match alignment.
Answer: B

21. Which of the following will always produce UB (undefined behavior)?
A) Accessing a struct member beyond its declared type via pointer casting to another incompatible struct type, violating strict aliasing.
B) Accessing any structure through a char* is UB.
C) Casting pointer to struct to pointer to first member and accessing it is UB.
D) Using memcpy to copy POD structs is UB.
Answer: A

22. Given:
struct S { int x; char y; };
struct T { int x; char y; };
Assuming same layout, which is true about converting struct S* to struct T* and dereferencing?
A) It is strictly conforming and always safe.
B) It violates strict aliasing and is undefined behavior.
C) It is allowed because layouts are identical.
D) It results in runtime type information check and may fail.
Answer: B

23. Which of the following allows you to access the bytes of a struct safely for serialization?
A) Cast the struct pointer to char* and read bytes directly (allowed).
B) Cast to int* and read words (allowed).
C) Use memcpy to/from a byte buffer (portable and safe).
D) Both A and C are equally portable.
Answer: C

24. Consider:
struct S { int a; double b; };
Which is correct about alignment of b?
A) b must be aligned on a double boundary as required by implementation.
B) b has no alignment requirement inside a struct.
C) b is always placed immediately after a with no padding.
D) b alignment depends only on sizeof(int).
Answer: A

25. What does the packed attribute (__attribute__((packed))) do to a struct?
A) Removes padding between members; may cause unaligned accesses.
B) Increases padding of members.
C) Makes struct read-only.
D) Converts the struct into a union.
Answer: A

26. Given:
struct A { char c; int i; } x;
Which expression yields the address of member i?
A) &x.i
B) (char*)&x + offsetof(struct A, i)
C) Both A and B
D) Neither A nor B
Answer: C

27. For structures containing function pointers, which statement is true?
A) Function pointer size equals data pointer size on all implementations.
B) Function pointers may have different sizes or representations than data pointers.
C) You cannot store function pointers in structs.
D) Function pointers cannot be assigned or compared.
Answer: B

28. Which of the following is a valid use of designated initializers (C99)?
A) struct S { int a,b,c; } s = {.b=2, .a=1};
B) struct S s = {.x=1}; when x not in S.
C) struct S s = {[2]=5}; for non-array struct.
D) struct S s = { .a = 1, 2 }; mixing designated and positional incorrectly.
Answer: A

29. Which of the following is true about arrays of structures?
A) Elements are contiguous and can be accessed via pointer arithmetic.
B) There is hidden pointer between elements.
C) Each struct in the array has additional header bytes.
D) Array of structs cannot contain flexible array members.
Answer: A

30. Which statement is true about memset(&s, 0, sizeof s) for a struct s?
A) It reliably zeroes out all members to represent their zero value.
B) Zeroing bytes sets pointer members to a guaranteed null pointer value.
C) It is implementation-defined whether pointer members become NULL.
D) Only integer members are guaranteed zero semantics; pointers may not be all-bits-zero for NULL.
Answer: D

31. Which technique produces a deep copy of a struct that contains dynamically allocated members?
A) Use memcpy from source to destination.
B) Implement a custom copy function that allocates new memory and copies pointed-to data.
C) Use assignment operator = for structs.
D) Cast to char* and copy bytes.
Answer: B

32. Which of the following statements is true about struct alignment when used in arrays?
A) Each element in an array of struct is aligned according to the struct’s alignment.
B) Only the first element is aligned; others follow tightly.
C) Compiler may insert padding between array elements to satisfy alignment.
D) Both A and C are correct.
Answer: D

33. Consider:
struct S { int a; char b; } __attribute__((aligned(16)));
What is the effect?
A) Each struct S will have an alignment requirement of 16 bytes.
B) Size is forced to 16 bytes always.
C) All members become 16-byte aligned individually.
D) No effect unless packed.
Answer: A

34. Which of the following allows a struct to contain another struct but with different memory footprint?
A) Embedding struct directly as member (struct A a;).
B) Storing pointer to struct (struct A *a;) and allocating separately.
C) Using union to overlay members.
D) Both A and B differ in footprint.
Answer: D

35. Which is true regarding compound literals with structs (C99)?
A) (struct S){1,2} creates an rvalue struct object usable in expressions.
B) Compound literals for structs cannot be created in C.
C) They produce pointers to static memory always.
D) They are identical to functions returning structs.
Answer: A

36. If a struct contains bit-fields that span an int boundary, which is true?
A) The compiler may pack them within the same underlying storage unit if the types match.
B) The compiler must split them across storage units always.
C) Bit-fields are always stored in char units.
D) Bit-fields cannot cross underlying storage boundaries.
Answer: A

37. Which is true about using sizeof on incomplete struct types?
A) sizeof an incomplete type is allowed and returns zero.
B) sizeof an incomplete type is a compile-time error.
C) sizeof returns the size of pointer for incomplete types.
D) sizeof works if you cast to void*.
Answer: B

38. Which scenario makes a struct type incomplete?
A) Declaring struct S; without definition.
B) Declaring a typedef alias for struct.
C) Declaring struct S { int x; };.
D) Using a flexible array member as last member.
Answer: A

39. Consider:
struct A { int x; };
struct B { struct A a; };
Which is true about sizeof(struct B)?
A) It equals sizeof(int).
B) It is at least sizeof(struct A) and possibly larger due to alignment.
C) It must be strictly larger than struct A.
D) It will always be equal to sizeof(struct A) + sizeof(void*).
Answer: B

40. Which of the following is a correct way to define an array of pointers to struct S and allocate 10 elements?
A) struct S **arr = malloc(10 * sizeof *arr);
B) struct S *arr = malloc(10 * sizeof *arr);
C) struct S *arr[10]; then arr = malloc(…);
D) struct S *arr = malloc(10 * sizeof(struct S*));
Answer: A

41. Regarding the strict aliasing rule, which is permitted?
A) Accessing any object through a pointer to char or unsigned char.
B) Accessing an int through a double*.
C) Accessing a float through int*.
D) Accessing a struct A through struct B* if layout matches.
Answer: A

42. Which of following operations on structs is guaranteed by the C standard to be valid?
A) Comparing two structs with ==.
B) Assigning one struct variable to another of the same type.
C) Using switch directly on a struct.
D) Taking the address of a bit-field.
Answer: B

43. Which of these is NOT a reason to use struct in C?
A) Group related data under a single type.
B) Simulate object-like encapsulation with private members enforced by the compiler.
C) Create heterogenous collections.
D) Model records in I/O.
Answer: B

44. Consider:
struct S { char c; /*padding*/ int i; };
Which is a legitimate technique to avoid padding between c and i while keeping portability?
A) Use #pragma pack(1) everywhere.
B) Place int i before char c.
C) Use char c:8; bit-field to eliminate padding.
D) Switch to a 32-bit platform.
Answer: B

45. What is the result of sizeof a struct with only a flexible array member, e.g. struct S { int n; char data[]; };?
A) It equals sizeof(int) — size of header only.
B) It is zero.
C) It depends on allocated trailing data.
D) It equals sizeof(int) + sizeof(data) where data is 0.
Answer: A

46. Which of the following statements is true about unions vs structs?
A) In a union, all members overlap starting at the same address; in a struct, members have distinct offsets.
B) Unions require more storage than structs with same members.
C) You can safely read any member of a union regardless of the last write (defined behavior).
D) Structs overlay members like unions do.
Answer: A

47. Consider:
struct S { int a; double b; };
struct S s = {.b = 1.0};
What is the value of s.a after initialization?
A) Indeterminate (garbage).
B) Zero, since unspecified members are zero-initialized.
C) Undefined behavior because a missing.
D) Compiler error.
Answer: B

48. Which statement about nested structures is correct?
A) Nested structs increase complexity without affecting alignment rules.
B) Embedded struct members are subject to alignment and may introduce padding in the containing struct.
C) Nested structs cause automatic deep copy of inner members on assignment.
D) Nested structs cannot be initialized with designated initializers.
Answer: B

49. Which of the following is true about structure tags and namespaces?
A) Tags (struct S) live in the same namespace as typedef names.
B) Tags live in a separate namespace from other identifiers.
C) You cannot have the same tag name and typedef name.
D) Tags are runtime-only constructs.
Answer: B

50. Which of the following is a correct way to declare a function that returns a pointer to a struct S?
A) struct S foo(void);
B) struct S *foo(void);
C) struct *S foo(void);
D) S *foo(void); (without typedef)
Answer: B

51. Consider pointer arithmetic on struct S *p;. Which is true about p + 1?
A) It advances by one byte.
B) It advances by sizeof(struct S) bytes.
C) It advances by the alignment of S.
D) Undefined behavior unless S is POD.
Answer: B

52. Which is true about const struct members?
A) Declaring a member const int x; in a struct prevents the compiler from initializing it.
B) Structs may contain const members, but you cannot assign to such a struct via = easily.
C) const members make the entire struct const automatically.
D) const members are stored in read-only memory always.
Answer: B

53. Regarding function parameters declared as struct S s vs struct S *s, which best practice is recommended for large structs?
A) Pass by value always; compilers optimize.
B) Pass by pointer to avoid copying and for performance reasons.
C) Pass by making global variable.
D) Use union instead.
Answer: B

54. Which of the following about memcpy(&dest, &src, sizeof src); is true when copying structs?
A) It’s a portable way to copy POD-like structs.
B) It always performs deep copy.
C) It is UB for structs with pointers.
D) It will call copy constructors.
Answer: A

55. Which of the following is true for a struct with a volatile member?
A) Reads/writes to that member are not optimized away and must happen as written.
B) volatile on member makes assignments to whole struct volatile-free.
C) volatile has no effect inside structs.
D) volatile enforces atomicity of access.
Answer: A

56. What is true about memcpy vs assignment for structs with overlapping memory?
A) Assignment is safe for overlapping objects.
B) memcpy has undefined behavior for overlapping source/destination; memmove should be used.
C) memcpy is always safe for overlapping structs.
D) Both are equivalent for overlapping regions.
Answer: B

57. Which of the following correctly creates an array of structs and initializes them?
A) struct S arr[2] = { {1,2}, {3,4} };
B) struct S arr[] = { (struct S){1,2} };
C) struct S *arr = { {1,2}, {3,4} };
D) Both A and B are correct forms.
Answer: D

58. Regarding the memory address of a struct and its first member:
A) The address of the struct equals the address of its first member.
B) The address of the struct may differ from its first member.
C) It’s undefined which is larger.
D) They must be different to allow polymorphism.
Answer: A

59. Which of the following will correctly swap two structs of the same type S s1, s2; without copying element-by-element?
A) struct S tmp = s1; s1 = s2; s2 = tmp;
B) memcpy(&tmp, &s1, sizeof s1); memcpy(&s1, &s2, sizeof s1); memcpy(&s2, &tmp, sizeof s1);
C) Using pointer swap struct S *p=&s1,*q=&s2; *p=*q;
D) Both A and B are correct; C is wrong.
Answer: D

60. Which of these is a correct reason to use offsetof macro?
A) To compute the offset of a member for container macros like container_of.
B) To compute pointer alignment.
C) To get the physical memory address.
D) To change member offsets at compile time.
Answer: A

61. When implementing a singly linked list using a struct with a next pointer, which is most important to avoid memory leaks?
A) Free nodes when removed and ensure no dangling pointers remain.
B) Use memset instead of free.
C) Keep all nodes allocated until program exit.
D) Use global arrays instead of malloc.
Answer: A

62. Which of these is true regarding compatibility of two struct types?
A) Two struct types are compatible if they have the same tag and compatible member lists.
B) Two structs with same layout but different tags are always compatible.
C) Compatibility is decided at runtime.
D) typedef names matter for compatibility.
Answer: A

63. Which is a correct pattern to embed an interface-like behavior in C using structs?
A) Include function pointers inside a struct to implement polymorphism.
B) Use inheritance like in C++ with struct extends.
C) Use macros to simulate classes only.
D) Use virtual keyword in struct.
Answer: A

64. Consider:
struct S { int a; int b; } s = { .b = 2 };
Which best describes the initialization of s.a?
A) s.a is zero-initialized.
B) s.a remains uninitialized (indeterminate).
C) Compiler error because .b used.
D) It gets the next value from .b.
Answer: A

65. Which is true about the C standard and pointer representation of a struct?
A) The standard guarantees struct pointers are aligned and dereferenceable when properly created.
B) The standard defines exact byte layout for structs.
C) The standard forbids pointer arithmetic on struct pointers.
D) The standard allows pointer-to-struct arithmetic to cross object boundaries.
Answer: A

66. For struct S { int a; double b; }, what does &( (struct S *)0 )->b produce technically?
A) A pointer equal to offsetof(struct S, b) cast to pointer type (used in container_of trick).
B) A valid dereference.
C) UB because of dereferencing null pointer.
D) Runtime crash always.
Answer: A

67. Which of the following is false about using qsort with arrays of structs?
A) You must provide the size of each element as sizeof element.
B) Compare function receives pointers to elements (i.e., pointers to structs).
C) qsort may swap elements using memcpy, so compare must not rely on pointer identity.
D) qsort requires that structs have no pointer members.
Answer: D

68. Which of the following best describes “type punning” via unions?
A) Using a union to reinterpret the same memory as different types; permitted in C with some caveats.
B) Always undefined behavior by the standard.
C) Only allowed for char type.
D) Always produces trap representations.
Answer: A

69. Which is a valid method to allocate a struct with flexible array member to hold N bytes?
A) struct S *p = malloc(sizeof *p + N);
B) struct S *p = malloc(sizeof(struct S) + N * sizeof p->data); when data type size known.
C) struct S *p = malloc(sizeof(struct S) + N * sizeof p->data[0]);
D) All of the above, depending on correct expression.
Answer: D

70. Which of the following about sizeof operator applied to an array of structs is correct?
A) sizeof arr / sizeof arr[0] gives the number of elements for array arr.
B) sizeof arr gives number of elements directly.
C) sizeof arr[0] gives always one.
D) sizeof cannot be used on arrays of structs.
Answer: A

71. Consider:
struct S { char c; int i; } x;
void *p = &x;
Which of the following is guaranteed by the standard?
A) (struct S *)p == &x after casting back.
B) Casting p back to struct S* yields pointer with same value as &x.
C) Casting p to char* and then back preserves pointer value.
D) Both B and C are true.
Answer: D

72. Which approach ensures alignment for a dynamically allocated struct with special alignment requirement?
A) Use posix_memalign or aligned_alloc to get required alignment.
B) Use malloc and assume it matches any alignment.
C) Use memset to align.
D) Place padding bytes manually after malloc.
Answer: A

73. Which statement about struct initializers in C is correct?
A) Unspecified members are zero-initialized if any initializer is present.
B) Unspecified members are left uninitialized.
C) The compiler randomly initializes them.
D) You must initialize all members explicitly.
Answer: A

74. Which of the following is true regarding const and struct assignment?
A) You cannot assign to a struct variable declared const.
B) Struct assignment ignores const on members.
C) const on a struct type prevents copying.
D) const only affects pointers, not struct content.
Answer: A

75. Which is true about structure member reordering by the compiler?
A) Compiler is not allowed to reorder members; their order is as written in the source.
B) Compiler may reorder members for performance.
C) Reordering is allowed under -O2.
D) Members are stored sorted by size automatically.
Answer: A

76. Consider:
struct S { int a; char b; } __attribute__((packed));
Which is a potential downside?
A) Unaligned accesses on architectures that require alignment may cause slower access or hardware fault.
B) It increases default alignment.
C) It prevents copying by assignment.
D) It makes the struct larger.
Answer: A

77. Which statement about using fread/fwrite with structs is true?
A) Writing binary struct directly is portable across different architectures.
B) It may be non-portable due to endianness, padding, and size differences.
C) It is always the recommended serialization format.
D) fread will convert endianness automatically.
Answer: B

78. What is true about nested unnamed (anonymous) unions inside structs in C11?
A) Their members are directly visible in the containing scope.
B) They require a name to be used.
C) They are not part of standard C.
D) They cause the struct to become a union.
Answer: A

79. For a struct with a function pointer member, what must be ensured before calling through it?
A) The function pointer must be assigned to a valid function address.
B) It must be non-NULL and compatible function type.
C) The calling convention must match the stored pointer.
D) All of the above.
Answer: D

80. Which of the following is true about structure padding and security (e.g., information leakage)?
A) Padding bytes may contain indeterminate values which could leak memory contents if written out.
B) Padding is always zero and safe.
C) Compiler always clears padding on initialization.
D) Padding cannot be exploited because it is inaccessible.
Answer: A

81. Which of these definitions is illegal?
A) struct S { int a; struct S *p; };
B) struct S { int a; struct S s2; };
C) struct S; typedef struct S S_t;
D) typedef struct { int x; } T;
Answer: B

82. Which is true about passing pointer to struct of one type as void*?
A) It is allowed and reversible by casting back to original pointer type.
B) It is UB to cast struct pointer to void*.
C) void* cannot refer to struct objects.
D) The standard forbids pointer casts.
Answer: A

83. Which is true about alignment requirements of structure members on x86-64 System V?
A) double is typically aligned to 8 bytes.
B) int is aligned to 4 bytes.
C) char has alignment 1.
D) All of the above.
Answer: D

84. Consider:
struct S { int a; int b; } s = { .a = 1, .b = 2 };
Which is true if you take sizeof s?
A) It equals the sum of sizes of members plus padding, generally 8 bytes under assumptions.
B) It is always 16 bytes.
C) It equals 2.
D) It is computed at runtime.
Answer: A

85. Which is a correct usage of container_of style macro in C (conceptual)?
A) Compute containing structure pointer from pointer to member using offsetof.
B) Use pointer arithmetic with sizeof member only.
C) Use memcmp to find container.
D) Use strcpy to copy addresses.
Answer: A

86. Which is true about copying a struct via memmove?
A) memmove is safe for overlapping source and destination.
B) memmove will perform deep copy semantics.
C) memmove cannot be used for structs with pointers.
D) memmove is only for arrays.
Answer: A

87. Consider struct S { char a[3]; int b; }; placed in an array. Which is true about element boundaries?
A) Each element boundary respects sizeof(struct S) including padding added for alignment.
B) Elements are placed back-to-back without padding.
C) Each element is aligned only to char.
D) Compiler may reorder members to avoid padding between array elements.
Answer: A

88. Which of the following best explains why struct layouts may differ across compilers?
A) Different alignment, packing, and ABI rules cause differences.
B) The C standard prescribes a single layout across implementations.
C) Struct layouts are defined by ISO and must match.
D) Layout differences only occur with #pragma.
Answer: A

89. Regarding portability of a packed struct over network:
A) Packed struct binary representation may not be portable due to alignment and endianness.
B) Packed always portable because no padding.
C) Packed prevents endian variations.
D) Packed makes data size bigger and therefore less portable.
Answer: A

90. Which of the following patterns help avoid undefined behavior with strict aliasing?
A) Use char* to inspect object representation.
B) Use memcpy for type punning.
C) Use unions carefully (implementation-defined but commonly used).
D) All of the above.
Answer: D

91. Which of these is true about zero-length arrays (a non-standard extension like int a[0];)?
A) They are a GCC extension and not standard C.
B) They are standardized in C99.
C) They allocate one element always.
D) They are safer than flexible array members.
Answer: A

92. What is the result of taking sizeof a pointer to a struct?
A) Size of pointer type (e.g., 8 on 64-bit), independent of struct size.
B) The size of the struct it points to.
C) Zero if struct incomplete.
D) Depends on number of members.
Answer: A

93. Which is true about initialization using designated initializers in aggregate nested structs?
A) You can designate nested fields using .outer.inner = value.
B) You cannot use designated initializers for nested aggregates.
C) Designators only work for arrays, not structs.
D) Designators must appear in declaration order for nested structs.
Answer: A

94. If two structs differ only by having different qualifiers like volatile on a member, are they compatible types?
A) Qualifiers on members affect compatibility; types may be incompatible.
B) They are always compatible.
C) volatile does not affect type system.
D) The qualifier on members is ignored for compatibility.
Answer: A

95. Which of the following is true about representation of signed bit-fields?
A) Whether int bit-field is signed or unsigned is implementation-defined when plain int is used.
B) The sign is always unsigned.
C) C standard requires two’s complement for bit-fields.
D) Bit-fields cannot be signed.
Answer: A

96. Which is true about passing a pointer to a struct member to function expecting void *?
A) It is allowed; you can cast any object pointer to void*.
B) It is forbidden by the standard.
C) Only allowed for non-volatile members.
D) Only allowed for the first member.
Answer: A

97. When using realloc on memory holding an array of structs, which is necessary to maintain validity?
A) Update pointers to elements if realloc moves the memory.
B) Pointers to elements remain valid automatically.
C) realloc cannot be used on arrays of structs.
D) realloc zeroes out new memory always.
Answer: A

98. Which is true about printf and printing entire struct directly?
A) There is no standard % specifier to print a whole struct; print members individually.
B) %S prints a struct by default.
C) You can use %p to print struct contents.
D) printf inspects struct layout automatically.
Answer: A

99. Which of the following is valid C for embedding a vtable-like structure into a struct?
A)
struct V { void (*f)(void*); };
struct Obj { struct V *v; int data; };
B) struct Obj { vtable v; int data; }; without definition.
C) struct Obj { void (*v)(void); int data; }; (single pointer only)
D) Embedding vtable is not possible in C.
Answer: A

100. Which of the following most accurately describes “padding bytes” inside a struct?
A) They are bytes inserted by compiler between members or at end to satisfy alignment; their initial content may be indeterminate.
B) They are always set to zero by the compiler.
C) They are reserved and cannot be accessed even via memcpy.
D) They are controlled via volatile.
Answer: A