C Programming — Structures & Unions
C language from basics to advanced placement prep
100 Questions 10 Topics Take Test
Advertisement
Showing 11–20 of 100 questions in Structures & Unions
What is the output of this complex code?
struct S { char c; int i; } s;
printf("%lu", sizeof(s));
A 5
B 8
C 6
D 4
Correct Answer:  B. 8
EXPLANATION

char(1 byte) + padding(3 bytes) + int(4 bytes) = 8 bytes due to alignment requirements.

Take Test
Consider this structure: struct Complex { int real; int imag; }; If you want to create an array of 100 such structures, which declaration is correct?
A struct Complex c[100];
B struct Complex *c = (struct Complex *)malloc(100);
C struct Complex c = {100};
D struct Complex c[100][100];
Correct Answer:  A. struct Complex c[100];
EXPLANATION

Option A correctly creates a static array of 100 structures. Option B creates a pointer (and allocates incorrect size).

Take Test
What is the purpose of using anonymous structures/unions?
A To reduce memory usage
B To access members without using the intermediate struct name
C To improve execution speed
D To hide members from external access
Correct Answer:  B. To access members without using the intermediate struct name
EXPLANATION

Anonymous structures allow direct member access without needing to reference the nested structure name.

Take Test
In a nested structure scenario like struct A contains struct B, how do you access a member of B from A's variable?
A a_var->b_member
B a_var.b_var.c_member
C Both A and B are correct depending on context
D a_var..c_member
Correct Answer:  C. Both A and B are correct depending on context
EXPLANATION

If B is embedded in A: a_var.b_var.member. If B is a pointer in A: a_var->b_var->member or a_var.b_ptr->member.

Take Test
Which of the following is a valid way to pass a structure to a function?
A Pass by value only
B Pass by pointer only
C Both pass by value and pass by pointer
D Pass by reference only
Correct Answer:  C. Both pass by value and pass by pointer
EXPLANATION

Structures can be passed by value (copying the entire structure) or by pointer (passing address) for efficiency.

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
What will happen if you try to compare two structures using the == operator directly?
A It compares all members automatically
B It results in a compilation error
C It returns the comparison of the first members only
D It compares the memory addresses of the structures
Correct Answer:  B. It results in a compilation error
EXPLANATION

C does not support direct comparison of structures using ==. You must compare members individually or use memcmp().

Take Test
Consider a structure with bit fields:
struct Flags {
unsigned int flag1 : 1;
unsigned int flag2 : 3;
unsigned int flag3 : 4;
};
What is the minimum size of this structure?
A 1 byte
B 2 bytes
C 4 bytes
D 8 bytes
Correct Answer:  C. 4 bytes
EXPLANATION

Bit fields must fit within an underlying integer type. Total bits = 8, which requires at least 4 bytes (one int on most systems).

Take Test
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
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