Veda Bites are swipeable micro-lessons — each one teaches exactly one
idea. The bites below come from this kit — swipe through them in the app.
💡 Key Idea
Struct vs Union: One Memory Rule Changes Everything
Same syntax, totally different memory.
A struct gives every member its own memory; a union makes all members share one block sized to the largest member.
↳ Struct = separate boxes; union = one box shared by many labels.
📖 Definition
Structure: A Named Bundle of Mixed Types
One name, many data types.
↳ A struct is a blueprint; each variable of that type gets its own copy of all members.
📖 Definition
Union: One Memory Block, Many Faces
All members, one address.
↳ A union saves memory but only one member holds a valid value at any moment.
📖 Definition
Pointer: A Variable That Holds an Address
Pointers don't store data — they store where.
↳ & gives an address; * follows it to the value.
💻 Code Example
Accessing Struct Members: Dot vs Arrow
Dot for values, arrow for pointers.
↳ Arrow operator = dereference + member access in one step.
💻 Code Example
Union in Action: Only One Value Survives
Write one member, lose the others.
Writing `d.f` overwrote the bytes that `d.i` was using — so reading `d.i` gives meaningless data.
↳ Never read a union member other than the one last written.
⚠️ Common Mistake
Reading the Wrong Union Member
This bug is silent and deadly.
↳ Unions demand discipline: know which member is live.
⚠️ Common Mistake
Forgetting to Initialize a Pointer
Wild pointers crash programs.
↳ An uninitialized pointer points to nowhere safe.
⚖️ Comparison
When to Choose Struct vs Union
Pick by memory, not by habit.
↳ Struct for records, union for memory-efficient variants.
⭐ Important Fact
sizeof Tells the Truth About Memory
One operator reveals the layout.
↳ Use `sizeof` to verify memory usage — never assume.
⚙️ Process
Passing a Struct to a Function via Pointer
Pointers avoid copying big structs.
↳ Passing by pointer is faster and lets the function modify the original.
🌍 Real World
Where Unions Shine: Embedded Systems
Every byte counts in firmware.
↳ Unions are a memory-saving tool, not a general-purpose container.
🛠️ Application
Pointers + Structs = Linked Lists
Self-referencing structs build data structures.
A struct containing a pointer to its own type is the foundation of linked lists, trees, and graphs.
↳ Self-referential structs are the building blocks of dynamic data structures.
🎯 Exam Tip
Exam Favourite: Size of a Union
This question appears every year.
↳ Union size = largest member; struct size = sum + padding.
🧠 Memory Trick
Remember: Struct = Stack, Union = Share
Two S-words, two rules.
Struct = Stack of separate boxes. Union = United (shared) memory. The first letter tells you the memory rule.
↳ Struct stacks members; union unites them in one block.