Home Subjects C Programming Structures & Unions

C Programming
Structures & Unions

C language from basics to advanced placement prep

34 Q 10 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 31–34 of 34
Topics in C Programming
What is the size of the following structure?
struct point { int x; int y; float z; };
A 9 bytes
B 12 bytes
C 8 bytes
D 16 bytes
Correct Answer:  B. 12 bytes
EXPLANATION

int x = 4 bytes, int y = 4 bytes, float z = 4 bytes. Total = 12 bytes (no padding in this case on most systems).

Test
Which keyword is used to define a structure in C?
A class
B struct
C record
D object
Correct Answer:  B. struct
EXPLANATION

The 'struct' keyword is used to define structures in C. 'class' is used in C++ and Java.

Test
What will be the output of sizeof(union test) if union has members: int a, char b, float c?
A 4 bytes
B 7 bytes
C 9 bytes
D 11 bytes
Correct Answer:  A. 4 bytes
EXPLANATION

Union size equals the size of its largest member. Here, both int and float are 4 bytes (largest), so sizeof(union test) = 4 bytes.

Test
What is the primary difference between a structure and a union in C?
A Structure allocates memory for all members, union shares memory among members
B Union allocates memory for all members, structure shares memory
C Both allocate same memory but structure is faster
D There is no difference, they are synonyms
Correct Answer:  A. Structure allocates memory for all members, union shares memory among members
EXPLANATION

In structures, each member gets its own memory space. In unions, all members share the same memory location, so only one member can hold a value at a time.

Test
IGET
IGET AI
Online · Exam prep assistant
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