Explore the best Structures and Unions Interview Questions with 50+ powerful, beginner-friendly to advanced examples. Boost your C skills and prepare with confidence.
If you’re preparing for a C or embedded systems interview, you must be ready for Structures and Unions Interview Questions. These topics look simple, but interviewers ask surprisingly tricky problems around memory layout, padding, alignment, nested usage, and differences between structures vs unions.
Whether you’re a beginner learning C or an experienced engineer brushing up for a system-level role, this guide gives you crystal-clear explanations, real examples, and practical scenarios that hiring managers love to ask .
If you’re learning C programming and want to strengthen your fundamentals before practicing Structures and Unions Interview Questions, you should explore this detailed beginner-friendly guide on structures: Structures in C – Complete Guide
It explains structure syntax, memory layout, padding, nesting, and real-world examples in a very simple way. Reading this will give you a strong foundation before jumping into advanced interview questions.
Introduction of Structures and Unions Interview Questions
C is powerful because it gives you full control over memory. With that power comes responsibility and interviewers test whether you truly understand memory behavior.
Two of the biggest tools in C for organizing and controlling memory layouts are:
- Structure
- Union
This article focuses on all levels of structured interview questions and answers, especially tailored for c interview questions on structures and unions that appear in companies like Qualcomm, STMicroelectronics, Samsung, NXP, KPIT, TCS, and more.
What Are Structures?
In simple words:
- A structure in C is a way to group different variables under one name.
- Each member of a structure gets its own memory.
Example
struct Employee {
int id;
float salary;
char grade;
};
Memory is allocated for all members separately.
What Are Unions?
A union is like a structure, but all variables share the same memory location.
Think of it like a single container used by multiple items—only one item can exist meaningfully at a time.
Example
union Data {
int id;
float value;
char ch;
};
Size = size of largest member.
This simple difference is the root of almost all structure and union interview questions.
Structures vs Unions
Let’s break it down:
| Feature | Structure | Union |
|---|---|---|
| Memory | Separate memory for each member | Shared memory for all |
| Size | Sum of all members (with padding) | Size of largest member |
| Usage | Store multiple values at once | Store one value at a time |
| Example Use | Employee records | Embedded protocol decoding |
You’ll often hear the term unions vs structures in C in interviews when discussing memory behavior.
Beginner-Level Structures and Unions Interview Questions
Let’s warm up with friendly, simple questions.
What is a structure in C?
A structure is a user-defined datatype that groups different datatypes under one name.
Great for modeling real-world things like employee, car, sensor, etc.
What is a union in C?
A union is similar to a structure, but all members share the same memory.
This is the simplest form of union questions asked in interviews.
Why do we use structures?
To store data logically and keep multiple variables grouped.
Why do we use unions?
To save memory, especially in:
- Embedded systems
- Protocol parsers
- Hardware registers
This is common in questions on unions in interviews.
What is the size of a structure and union?
- Structure → sum of members + padding
- Union → size of largest member
Can a structure contain another structure?
Yes. This leads to nested structures, a common part of structural questions examples.
Can a union contain another union?
Yes, but rarely used unless memory reuse is needed.
Intermediate-Level Structure and Union Interview Questions
Here we get into deeper concepts like padding, alignment, pointers, typedef, and passing structures to functions.
How does padding affect structures?
C aligns structure members to the CPU’s natural alignment.
This affects size and layout.
Example:
struct test {
char a; // 1 byte
int b; // 4 bytes
};
Size is 8 bytes, not 5, because of alignment.
Can we remove structure padding?
Yes, using:
#pragma pack(1)__attribute__((packed))(GCC)
How to pass a structure to a function?
Three ways:
- By value
- By pointer
- By reference using pointer
Can we compare two structures directly?
No.
You must compare member-wise.
What happens if you read one union member after writing another?
This is undefined behavior.
This comes up in structures and unions in C interview questions and answers.
How does a union save memory?
Because it allocates memory only once for the largest member.
When should you choose structures vs unions
Use structure when you need multiple values at the same time.
Use union when you need different interpretations of the same memory block.
Advanced Structures and Unions Interview Questions and Answers
These are the tricky questions interviewers love to ask.
Explain memory layout of structure vs union
Structure:
| a | b | c |
Union:
| shared memory |
What is a flexible array member?
Used to create dynamic-sized structure:
struct packet {
int size;
char data[];
};
Why do embedded systems use unions for register mapping?
Because hardware registers can be accessed in multiple formats.
Example:
union Register {
uint32_t value;
struct {
uint32_t flag1:1;
uint32_t flag2:1;
uint32_t mode:2;
} bits;
};
Can a union have bitfields?
Yes.
Very important in systems programming.
Can a structure contain a union and vice-versa?
Yes, example:
struct Packet {
int type;
union {
int id;
float value;
} data;
};
What is union-intersection test example?
Example:
Say you have two sets:
A = {1,2,3}
B = {2,3,4}
Intersection = {2,3}
A union B = {1,2,3,4}
Used in questions around union-intersection test example.
Explain real-life use of union in protocol parsing
Protocols often require interpreting the same data as:
- bytes
- words
- floats
- struct of bits
Unions let us do that efficiently.
Can we initialize multiple union members?
No.
Only the last initialized member holds valid data.
How does endianness affect structures and unions?
Very common question.
Union endianness example:
union test {
int x;
char ch[4];
};
Real-World Embedded Use Cases
Interviewers are impressed when you explain real embedded usage.
Use Case 1: Sensor Packet Parsing
Unions help reinterpret raw bytes as structured data.
Use Case 2: Memory Optimization
In microcontrollers with limited RAM, unions reduce RAM footprint.
Use Case 3: Register Access
Mapping hardware registers using bitfields inside unions is extremely common.
Use Case 3: Variant Message Types
Example:
struct Message {
int type;
union {
int temp;
float pressure;
char status;
} data;
};
More Deep Interview Questions on Structure and Union in C
Below is a rich list of questions helpful for Qualcomm, Samsung, and system interviews.
Why cannot we take size of incomplete structure?
Because compiler doesn’t yet know memory layout.
What is self-referencing structure?
A structure that contains pointer to itself:
struct node {
int data;
struct node *next;
};
Difference between typedef struct and struct?
typedef gives alias.
No functional difference.
Are structures stored in stack or heap?
Depends:
- Local → stack
- Dynamically allocated → heap
Can we copy a structure using memcpy?
Yes—but be careful with pointers.
Is accessing union data type-safe?
No, union is inherently unsafe if misused.
What are structure padding and alignment?
Padding = unused bytes inserted for alignment.
Alignment = data placed at addresses divisible by data size.
50+ Structures and Unions Interview Questions
Beginner-Level Questions (Basics)
- What is a structure in C?
- What is a union in C?
- What is the difference between structure and union?
- How is memory allocated in a structure?
- How is memory allocated in a union?
- Can we declare arrays inside a structure?
- Can we declare arrays inside a union?
- Can a structure hold multiple data types?
- Can a union hold multiple data types?
- What is the size of an empty structure?
- What is the size of an empty union?
- Can a structure contain another structure?
- Can a union contain another union?
- Can a structure contain a union?
- Can a union contain a structure?
To thoroughly understand the answers to these 15 questions, explore our detailed article: Structure and Union Interview Questions in C: Master Practice Set #1
Intermediate-Level Questions (Memory, Padding, Function Calls)
- What is structure padding?
- What is structure alignment?
- What is structure packing?
- How to disable structure padding?
- Why does padding exist in structures?
- Why do unions not have padding between members?
- Can we compare two structures using == operator?
- Can we compare two union variables using == operator?
- How do you pass a structure to a function?
- How do you return a structure from a function?
- Can a structure be initialized at the time of declaration?
- Can a union be initialized at the time of declaration?
- What happens if we read a union member that was not last written?s
- What is a pointer to a structure?
- What is the arrow operator (->) used for?
- What is a typedef structure?
- What is a flexible array member in a structure?
- What are bitfields in structures?
- Can unions contain bitfields?
To thoroughly understand the answers of Intermediate-Level Questions explore our detailed article: Structure and Union Interview Questions in C: Master Practice Set #1
Advanced-Level Questions (Embedded, Type Punning, Internals)
- How do you calculate the size of a structure manually?
- How do you calculate the size of a union manually?
- What is the maximum alignment requirement in a structure?
- What is the advantage of using unions in embedded systems?
- What is type punning using union?
- What is the effect of endianness in unions?
- What are tagged unions?
- What is a self-referential structure?
- How do you allocate memory dynamically for structures?
- Can we use memcpy() with structures?
- Why is it risky to use unions for type-casting?
- What is the layout of structure members in memory?
- What is the layout of union members in memory?
- Can a structure be packed differently on different compilers?
- Are unions guaranteed to store overlapping memory?
- What happens when structure members have mixed datatypes (char, int, float)?
- How do you map hardware registers using structures?
- How do you map hardware registers using unions?
- Why do protocols use unions for parsing data?
- What is offsetof() macro and how is it used with structures?
- How is bit-endianness handled inside a union bitfield?
- Can structures be used to implement linked lists, stacks, and trees?
- Why is structure assignment more expensive than union assignment?
- Can unions be used to interpret raw data packets?
- What is the difference between unions vs structures in handling memory failures?
To thoroughly understand the answers of Advanced-Level Questions, explore our detailed article: Structure and Union Interview Questions in C: Master Practice Set #1
FAQ of Structures and Unions Interview Questions
Q1: What are the most common Structures and Unions Interview Questions?
Questions on memory layout, padding, size, nested usage, unions vs structures, and bitfields are the most common.
Q2: Why do interviewers ask questions about structures and unions in C?
Because these reveal your understanding of memory, alignment, and low-level behavior.
Q3: What’s the main difference between structures vs unions in C?
Structure stores all members; union stores only one member at a time.
Q4: How do unions save memory?
Because all members share the same location.
Q5: Are unions used in embedded systems?
Yes, especially for register access and protocol parsing.
Q6: Do structures have padding?
Yes, for alignment.
Q7: Can we remove padding?
Yes, using packed attributes.
Q8: What are common c interview questions on structures and unions?
Size calculation, memory layout, bitfields, casting, union type punning.
Q9: Is union safe to use?
Only if used correctly.
Q10: What are structured interview questions and answers?
These are standardized questions asked in HR interviews.
Q11: What are union structures in organizational context?
Local, regional, national labor union structures.
Conclusion
If you read this entire guide, you now understand:
- Structures and unions in C
- Differences between structures vs unions
- Memory layout, padding, alignment
- Beginner to advanced structure and union interview questions in C
- Real-world embedded usage
- A long list of practice questions
Mr. Raj Kumar is a highly experienced Technical Content Engineer with 7 years of dedicated expertise in the intricate field of embedded systems. At Embedded Prep, Raj is at the forefront of creating and curating high-quality technical content designed to educate and empower aspiring and seasoned professionals in the embedded domain.
Throughout his career, Raj has honed a unique skill set that bridges the gap between deep technical understanding and effective communication. His work encompasses a wide range of educational materials, including in-depth tutorials, practical guides, course modules, and insightful articles focused on embedded hardware and software solutions. He possesses a strong grasp of embedded architectures, microcontrollers, real-time operating systems (RTOS), firmware development, and various communication protocols relevant to the embedded industry.
Raj is adept at collaborating closely with subject matter experts, engineers, and instructional designers to ensure the accuracy, completeness, and pedagogical effectiveness of the content. His meticulous attention to detail and commitment to clarity are instrumental in transforming complex embedded concepts into easily digestible and engaging learning experiences. At Embedded Prep, he plays a crucial role in building a robust knowledge base that helps learners master the complexities of embedded technologies.












