Structures, Unions & Pointers in C: 18 flashcards

All 18 flashcards from this kit, free and with no sign-up.

1. What is a structure in C?

Show the answer

A user-defined data type that groups variables of different types under one name.

2. Which operator accesses members of a structure variable?

Show the answer

The dot operator (`.`), e.g., `s.roll`.

3. Which operator accesses members through a pointer to a structure?

Show the answer

The arrow operator (`->`), e.g., `p->roll`.

4. What is `p->member` shorthand for?

Show the answer

`(*p).member`

5. Why might `sizeof(struct T)` be larger than the sum of its members?

Show the answer

Because of padding added for memory alignment.

6. How is a union stored in memory?

Show the answer

All members share the same memory location.

7. What is the size of a union?

Show the answer

The size of its largest member.

8. How many union members are valid at a time?

Show the answer

Only one — the last one written.

9. When should you use a union instead of a structure?

Show the answer

When a variable holds one of several types but never more than one at a time, or to save memory.

10. What is a self-referential structure?

Show the answer

A structure containing a pointer to its own type, used to build linked lists, trees, etc.

11. What is the safe default for passing large structures to functions?

Show the answer

Pass by `const` pointer to avoid copying and prevent modification.

12. What happens when you pass a structure by value?

Show the answer

The entire structure is copied.

13. Why is `*p.member` wrong?

Show the answer

Because `.` binds tighter than `*`, so it parses as `*(p.member)`, not `(*p).member`.

14. What is a tagged union?

Show the answer

A structure combining a tag field with a union to represent variant types safely.

15. What is padding in structures?

Show the answer

Unused bytes inserted between members to satisfy alignment requirements.

16. How can you reduce padding in a structure?

Show the answer

Reorder members from largest to smallest.

17. Give a practical use of unions in embedded systems.

Show the answer

Register overlays: same bits accessed as a word or as bytes.

18. What is the result of reading a union member other than the last written?

Show the answer

The bytes are reinterpreted; the result is not portable and usually not what you want.

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