C Programming — Structures & Unions
C language from basics to advanced placement prep
34 Questions 10 Topics Take Test
Advertisement
Showing 1–10 of 34 questions in Structures & Unions
Given a structure with array members, how would you efficiently pass it to a function to avoid copying overhead?
A Pass by value directly
B Pass a pointer to the structure
C Use typedef with the structure
D Convert 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.

Take Test
struct Node { int data; struct Node *next; }; This is an example of which design pattern?
A Recursive structure
B Self-referential structure
C Circular structure
D Polymorphic 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.

Take Test
What is the key difference between a structure and a union in C?
A Union allocates memory for all members simultaneously, structure allocates for each member separately
B Structure allocates memory equal to sum of all members, union allocates memory equal to the largest member
C Union can have function pointers, structure cannot
D Structure 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.

Take Test
In the context of structures, what does 'self-referential' mean?
A A structure that contains a member of the same structure type
B A structure that refers to global variables
C A structure that contains only pointers
D A structure defined within another structure
Correct Answer:  A. A structure that contains a member of the same structure type
EXPLANATION

Self-referential structures contain pointers to their own type, enabling dynamic data structures like linked lists and trees.

Take Test
Given: struct Node { int data; struct Node *next; }; This represents which data structure concept?
A Binary Tree node
B Singly Linked List node
C Graph adjacency node
D Hash table bucket
Correct Answer:  B. Singly Linked List node
EXPLANATION

A self-referential structure with a single pointer member is the fundamental building block of a singly linked list.

Take Test
Advertisement
In C, what does the 'typedef' keyword do when used with structures?
A Creates a new data type that is an alias for the structure
B Allocates memory for the structure
C Makes the structure accessible globally only
D Prevents the structure from being modified
Correct Answer:  A. Creates a new data type that is an alias for the structure
EXPLANATION

typedef creates an alias, allowing you to use the structure name directly without using 'struct' keyword.

Take Test
Which of the following correctly demonstrates accessing a member of a pointer to a structure?
A ptr.member
B (*ptr).member
C **ptr.member
D ptr->member->member
Correct Answer:  B. (*ptr).member
EXPLANATION

Both (*ptr).member and ptr->member are valid. Option B uses explicit dereferencing, while the arrow operator is syntactic sugar for this.

Take Test
What is the primary difference between a struct and a union in C?
A Struct members are stored sequentially; union members share the same memory location
B Union members are stored sequentially; struct members share memory
C Both allocate separate memory for each member
D There is no functional difference
Correct Answer:  A. Struct members are stored sequentially; union members share the same memory location
EXPLANATION

In a union, all members occupy the same memory space, while struct members have individual memory locations.

Take Test
Consider the following code:
struct Data {
int a;
char b;
};
struct Data d = {10, 'A'};
Which method of initialization is used here?
A Designated initialization
B Positional initialization
C Named initialization
D Array initialization
Correct Answer:  B. Positional initialization
EXPLANATION

Values are assigned in the order they appear in the structure definition, which is positional initialization.

Take Test
Which of the following statements about structures is TRUE?
A A structure is a collection of variables of the same data type
B A structure is a collection of variables of different data types grouped under a single name
C A structure cannot contain pointers
D A structure occupies memory equal to the sum of its members without any padding
Correct Answer:  B. A structure is a collection of variables of different data types grouped under a single name
EXPLANATION

A structure allows grouping of different data types. Padding may be added by the compiler for alignment.

Take Test
IGET
iget AI
Online · Ask anything about exams
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips