Given a structure with array members, how would you efficiently pass it to a function to avoid copying overhead?
APass by value directly
BPass a pointer to the structure
CUse typedef with the structure
DConvert to union before passing
Correct Answer:
B. Pass a pointer to the structure
EXPLANATION
Passing a pointer to the structure avoids copying the entire structure in memory, which is especially important for large structures with array members. This improves performance significantly.
struct Node { int data; struct Node *next; }; This is an example of which design pattern?
ARecursive structure
BSelf-referential structure
CCircular structure
DPolymorphic structure
Correct Answer:
B. Self-referential structure
EXPLANATION
A self-referential structure contains a pointer to its own type. This is the fundamental building block for creating linked lists, trees, and other dynamic data structures.
What is the key difference between a structure and a union in C?
AUnion allocates memory for all members simultaneously, structure allocates for each member separately
BStructure allocates memory equal to sum of all members, union allocates memory equal to the largest member
CUnion can have function pointers, structure cannot
DStructure supports inheritance, union does not
Correct Answer:
B. Structure allocates memory equal to sum of all members, union allocates memory equal to the largest member
EXPLANATION
In structures, memory is allocated for each member independently. In unions, all members share the same memory location, so total memory allocated equals the size of the largest member.