PRACTICE • LEARN • GROW
Module 9: Structures and Unions - Final Quiz MCQs
Solve topic-wise placement questions and improve your skills.
Module 9: Structures and Unions - Final Quiz Progress
0 of 11 completed
0%
Topic Track
You are viewing MCQs in preview mode. Log in to select options, submit answers, and track your progress.
Log In to Answer
1
What is the size of the following structure on a standard 32/64-bit architecture with 4-byte integer alignment?
#include <stdio.h>
struct Example {
char a;
int b;
char c;
};
int main() {
printf("%zu", sizeof(struct Example));
return 0;
}
A.
6
B.
12
C.
8
D.
16
Explanation & Key
Correct Answer:
2
How much memory is saved by reordering the struct members as shown below?
#include <stdio.h>
struct Optimized {
int b;
char a;
char c;
};
int main() {
printf("%zu", sizeof(struct Optimized));
return 0;
}
A.
6 (saves 6 bytes)
B.
8 (saves 4 bytes compared to 12 bytes)
C.
12 (no change in size)
D.
10
Explanation & Key
Correct Answer:
3
What is the size of the following union in memory?
#include <stdio.h>
union Packet {
int id;
double timestamp;
char tag[10];
};
int main() {
printf("%zu", sizeof(union Packet));
return 0;
}
A.
22 (sum of all members)
B.
10 (size of tag)
C.
16 (largest member tag[10] padded to double's 8-byte alignment)
D.
8
Explanation & Key
Correct Answer:
4
What is the output of the following union member overwriting on a standard little-endian machine?
#include <stdio.h>
union Value {
int num;
char ch;
};
int main() {
union Value v;
v.num = 512;
v.ch = 'A'; // ASCII 65
printf("%d", v.num);
return 0;
}
A.
512
B.
577
C.
65
D.
0
Explanation & Key
Correct Answer:
5
What is the difference between the
. (dot) operator and the -> (arrow) operator?
A.
. is used for structures, -> is used for unions
B.
. accesses a member from a struct variable directly; -> accesses a member through a pointer to a struct
C.
. is runtime only; -> is compile-time
D.
. is deprecated in ANSI C
Explanation & Key
Correct Answer:
6
Why must self-referential structures (e.g. Linked List nodes) use a pointer to the structure type rather than a direct structure instance member?
A.
Because pointers consume less CPU cache
B.
Because a direct instance would create an infinitely recursive type definition of indeterminate size at compile time
C.
Because C compilers disallow the struct tag name inside its definition
D.
Because pointers automatically allocate heap memory
Explanation & Key
Correct Answer:
7
What range of integer values can the priority bit-field hold?
struct Header {
unsigned int is_active : 1;
unsigned int priority : 3;
};
A.
0 to 3
B.
0 to 7
C.
-4 to 3
D.
0 to 8
Explanation & Key
Correct Answer:
8
Can you take the memory address of a bit-field member using the address-of operator
& (e.g. &h.priority)?
A.
Yes, always
B.
No — bit-fields do not have individual byte addresses in physical memory and taking their address causes a compile error
C.
Yes, but only with a void* pointer
D.
Only if the bit-field is 8 bits wide
Explanation & Key
Correct Answer:
9
What is the output of structure assignment in the following code?
#include <stdio.h>
struct Point { int x, y; };
int main() {
struct Point p1 = {10, 20};
struct Point p2 = p1;
p2.x = 99;
printf("%d %d", p1.x, p2.x);
return 0;
}
A.
99 99
B.
10 99
C.
10 20
D.
Compile error
Explanation & Key
Correct Answer:
10
What is the primary benefit of using
typedef when defining a C structure?
A.
It moves the struct from stack to heap
B.
It creates a convenient type alias, eliminating the requirement to type the
struct keyword on every variable declaration
C.
It disables struct padding
D.
It makes all members constant
Explanation & Key
Correct Answer:
11
How many members of a union can store valid, meaningful data simultaneously during runtime?
A.
All declared members
B.
Exactly two members
C.
Only one member at any given instant
D.
None
Explanation & Key
Correct Answer:
Question Palette
Answered
Current
Not Attempted
Wrong