C Programming — Structures & Unions
C language from basics to advanced placement prep
46 Questions 10 Topics Take Test
Advertisement
Showing 1–10 of 46 questions in Structures & Unions
Which of the following statements about structure initialization in C is INCORRECT?
A Designated initializers allow setting members in any order
B All members must be explicitly initialized during declaration
C Members can be initialized during structure definition
D Partial initialization results in uninitialized members having indeterminate values
Correct Answer:  B. All members must be explicitly initialized during declaration
EXPLANATION

Members do not need to be explicitly initialized. Uninitialized members in automatic structures have indeterminate values, while static structures have zero-initialized members. Designated initializers (C99+) allow flexible initialization order.

Take Test
In the context of bit fields in structures, what is the maximum number of bits that can be allocated to a single member in standard C?
A 8 bits
B 16 bits
C Size of the underlying type in bits
D 32 bits
Correct Answer:  C. Size of the underlying type in bits
EXPLANATION

The maximum number of bits for a bit field member cannot exceed the size of the underlying type. For int (typically 32 bits), you can allocate up to 32 bits to a single member.

Take Test
Which feature in C allows you to define a structure without a tag name for use within another structure?
A Tagged union
B Anonymous structure
C Typedef structure
D Nested enumeration
Correct Answer:  B. Anonymous structure
EXPLANATION

Anonymous structures allow defining structures without a tag name directly inside another structure, making members accessible as if they belong to the outer structure.

Take Test
Consider the following code:
struct Data {
int x;
char y;
double z;
};
Assuming int=4 bytes, char=1 byte, double=8 bytes, what is the size of struct Data due to padding?
A 13 bytes
B 16 bytes
C 20 bytes
D 24 bytes
Correct Answer:  D. 24 bytes
EXPLANATION

Memory alignment causes padding. x(4) + padding(4) + y(1) + padding(7) + z(8) = 24 bytes. The compiler aligns to the largest member (double = 8 bytes).

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
Advertisement
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
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
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