Structures, Unions & Pointers in C: 17 MCQs with answers
All 17 multiple-choice questions from this kit, free and with no sign-up.
Warm-up · 6 questions
Q1. Which of the following best describes a structure in C?
BeginnerShow the answer
A · A collection of variables of different types under one name
A structure groups variables of different types under a single name, unlike an array which holds same-type elements.
Q2. Given `struct Student s;`, how do you access the `roll` member?
BeginnerShow the answer
B · `s.roll`
For a structure variable, use the dot operator: `s.roll`.
Q3. What is the size of a union?
BeginnerShow the answer
A · Size of the largest member
All union members share the same memory, so the union's size is that of its largest member.
Q4. Which operator is used to access a structure member through a pointer?
BeginnerShow the answer
D · Arrow (`->`)
The arrow operator `->` accesses members via a pointer, e.g., `p->member`.
Q5. What does `p->member` mean?
BeginnerShow the answer
D · `(*p).member`
`p->member` is shorthand for `(*p).member`; the parentheses are required because `.` binds tighter than `*`.
Q6. The size of a union equals the size of its largest member, because all members share the same memory location.
BeginnerShow the answer
A · True
The size of a union equals the size of its largest member, because all members share the same memory location.
Building up · 6 questions
Q7. Why might `sizeof(struct T)` be larger than the sum of its members?
IntermediateShow the answer
B · Because of padding for alignment
The compiler inserts padding bytes to align members to natural boundaries, increasing the total size.
Q8. In a union, which member is valid after writing to one member?
IntermediateShow the answer
D · Only the last written member
Union members overlap; writing one overwrites the others. Only the most recently written member is meaningful.
Q9. What is the primary reason to pass a large structure to a function by pointer?
IntermediateShow the answer
A · To avoid copying the entire structure
Passing by pointer passes only an address, avoiding the cost of copying all bytes. Modification is a separate benefit.
Q10. Which of the following is a self-referential structure?
IntermediateShow the answer
D · `struct Node { int data; struct Node *next; };`
A self-referential structure contains a pointer to its own type, enabling linked data structures.
Q11. What is the effect of `const struct T *p` in a function parameter?
IntermediateShow the answer
D · The data pointed to cannot be modified through `p`
`const struct T *p` means the pointed-to data is read-only through `p`; the pointer itself can change.
Q12. Which of the following is a common use of a union?
IntermediateShow the answer
D · Representing a value that can be an int, float, or string at different times
Unions are ideal for variant data where only one type is active at a time.
Topper level · 5 questions
Q13. What is wrong with `*p.member` when `p` is a pointer to a structure?
AdvancedShow the answer
A · It parses as `*(p.member)`, which is incorrect
The dot operator has higher precedence than `*`, so `*p.member` means `*(p.member)`, not `(*p).member`.
Q14. How can you reduce padding in a structure?
AdvancedShow the answer
D · Reorder members from largest to smallest
Placing larger members first often minimizes padding because alignment gaps are reduced.
Q15. What is a tagged union?
AdvancedShow the answer
D · A union with a tag field indicating which member is active
A tagged union combines a tag (often an enum) with a union to safely track the active member.
Q16. Reading a union member other than the last written one is:
AdvancedShow the answer
C · Not portable and usually not what you want
The bytes are reinterpreted according to the new type; the result depends on representation and is not portable.
Q17. Given the following code snippet, what will be the output when `show(&student1);` is called, assuming `student1` has been initialized with `roll = 10`, `name = 'John'`, and `marks = 85.5`? ```c struct Student { char name[30]; int roll; float marks; }; void show(struct Student *p) { printf("%d", p->roll); } ```
AdvancedShow the answer
B · 10
The correct option is '10' because the `show` function accesses the `roll` member of the `Student` structure using the pointer `p` and the arrow operator `->`, which correctly dereferences to the `roll` member.
Your notes can be a kit like these
Every kit here was made from real study material. Point Veda at a chapter, a PDF, a photo or a link and get notes, flashcards, practice MCQs, games and a scored test — free, in 42 languages.
- Chapter notes
- Flashcards
- Practice MCQs
- Scored tests
- Exam prep
Get Veda free See what students get
Free to start · No ads · Works in 42 languages