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?

Beginner
A A collection of variables of different types under one name
B A memory area shared by all members
C A collection of variables of the same type
D A pointer to another structure
Show 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?

Beginner
A `s->roll`
B `s.roll`
C `s[roll]`
D `*s.roll`
Show the answer

B · `s.roll`

For a structure variable, use the dot operator: `s.roll`.

Q3. What is the size of a union?

Beginner
A Size of the largest member
B Size of the smallest member
C Sum of all member sizes
D Always 4 bytes
Show 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?

Beginner
A Ampersand (`&`)
B Dot (`.`)
C Asterisk (`*`)
D Arrow (`->`)
Show the answer

D · Arrow (`->`)

The arrow operator `->` accesses members via a pointer, e.g., `p->member`.

Q5. What does `p->member` mean?

Beginner
A `p.member`
B `*(p.member)`
C `&p.member`
D `(*p).member`
Show 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.

Beginner
A True
B False
Show 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?

Intermediate
A Because the compiler stores member names
B Because of padding for alignment
C Because structures always add a header
D Because pointers are stored for each member
Show 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?

Intermediate
A Only the first member
B None of the members
C All members remain valid
D Only the last written member
Show 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?

Intermediate
A To avoid copying the entire structure
B To make the code shorter
C To allow the function to modify the original
D To enable recursion
Show 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?

Intermediate
A `struct Node { int data; };`
B `struct Node { int data; union { int x; }; };`
C `struct Node { int data; struct Node next; };`
D `struct Node { int data; struct Node *next; };`
Show 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?

Intermediate
A The structure is copied to a new location
B The pointer cannot be reassigned, but data can be modified
C The structure is passed by value
D The data pointed to cannot be modified through `p`
Show 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?

Intermediate
A Building a linked list
B Storing a student record with name, roll, and marks
C Passing large structures to functions
D Representing a value that can be an int, float, or string at different times
Show 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?

Advanced
A It parses as `*(p.member)`, which is incorrect
B It is equivalent to `p->member`
C It dereferences the member value
D It is a syntax error because `*` cannot precede a pointer
Show 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?

Advanced
A Declare all members as `char`
B Use a union instead
C Use `#pragma pack(1)` always
D Reorder members from largest to smallest
Show 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?

Advanced
A A union with a pointer to itself
B A structure containing only a union
C A union that stores all members simultaneously
D A union with a tag field indicating which member is active
Show 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:

Advanced
A Always safe and portable
B Guaranteed to return zero
C Not portable and usually not what you want
D A compile-time error
Show 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); } ```

Advanced
A John
B 10
C Error: Cannot access roll
D 85.5
Show 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.

Make your own

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