Home Subjects C Programming Structures & Unions

C Programming
Structures & Unions

C language from basics to advanced placement prep

100 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 71–80 of 100
Topics in C Programming
Which statement is correct about bit fields in structures?
A They can be applied to any data type
B They are used to pack multiple members into fewer bytes
C They increase the structure size
D They make structures faster to access
Correct Answer:  B. They are used to pack multiple members into fewer bytes
EXPLANATION

Bit fields allow you to specify the number of bits for integral members, enabling memory optimization by packing multiple small values into a single byte.

Take Test
What happens when you modify a union member that overlaps with another?
A Both members update independently
B The previous member value is preserved
C The previous member's value gets overwritten
D A compilation error occurs
Correct Answer:  C. The previous member's value gets overwritten
EXPLANATION

Since union members share memory, modifying one member overwrites the value of other members because they occupy the same memory location.

Take Test
Which of the following correctly initializes a structure array? struct point { int x, y; } arr[3] = ?
A { {1,2}, {3,4}, {5,6} }
B { 1,2,3,4,5,6 }
C [ {1,2}, {3,4}, {5,6} ]
D None of the above
Correct Answer:  A. { {1,2}, {3,4}, {5,6} }
EXPLANATION

Structure arrays are initialized with nested braces, where each set of braces contains initialization values for one structure element.

Take Test
What is the primary advantage of using structures in C?
A To reduce program execution time
B To group related data of different types together
C To automatically initialize variables
D To prevent memory leaks
Correct Answer:  B. To group related data of different types together
EXPLANATION

Structures allow you to combine multiple data types into a single composite type, making code organization and data management more efficient.

Take Test
In a nested structure, how do you access the innermost member? struct outer { struct inner { int value; } in; } obj;
A obj.value
B obj.in.value
C obj->in->value
D obj.in->value
Correct Answer:  B. obj.in.value
EXPLANATION

For nested structures accessed through an object, use the dot operator multiple times: obj.in.value accesses the value member of the inner structure.

Take Test
What will be printed by this code? struct s { int a; struct s *next; }; struct s *ptr; sizeof(struct s)
A 4 bytes
B 8 bytes
C 12 bytes
D 16 bytes
Correct Answer:  C. 12 bytes
EXPLANATION

sizeof(int) = 4 bytes, sizeof(pointer) = 8 bytes (on 64-bit systems). Total = 12 bytes. Pointers are fixed size regardless of what they point to.

Take Test
Consider struct test { int x; double y; char z; }; What is the minimum size of this structure (assuming 4-byte int, 8-byte double)?
A 13 bytes
B 16 bytes
C 20 bytes
D 24 bytes
Correct Answer:  D. 24 bytes
EXPLANATION

Due to padding: int (4) + padding (4) + double (8) + char (1) + padding (3) = 24 bytes. The structure aligns to the largest member size.

Take Test
How do you access a structure member through a pointer in C?
A ptr.member
B ptr->member
C *ptr.member
D &ptr->member
Correct Answer:  B. ptr->member
EXPLANATION

The arrow operator (->) is used to access structure members through a pointer. It dereferences the pointer and accesses the member in one operation.

Take Test
What is the purpose of padding in C structures?
A To reduce memory usage
B To align data members on word boundaries for efficient access
C To increase security of the structure
D To prevent structure modification
Correct Answer:  B. To align data members on word boundaries for efficient access
EXPLANATION

Padding adds unused bytes between members to align them on word boundaries, improving CPU access efficiency and performance.

Take Test
Which keyword is used to define a new name for a structure in C?
A define
B typedef
C alias
D rename
Correct Answer:  B. typedef
EXPLANATION

The typedef keyword creates an alias for a data type, allowing you to use a shorter name instead of the full struct declaration.

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