Home›Learn›C›C Unions
C PROGRAMMING MASTER COURSEBEGINNER FRIENDLY

C Unions

Learn C Unions with simple explanations, practical examples, coding practice, MCQs and interview preparation.

📖 Chapter 15 / 22⏱️ 8–10 Min Read🎯 Beginner Friendly
Course Progress68%
📘

Theory

Understand the concept step by step

Unions in C

A union is similar to a structure, but all members share the same memory location.

Syntax

union Data {
    int number;
    float price;
    char letter;
};

A union can store a value for one member at a time.

The size of a union is generally determined by its largest member, subject to alignment requirements.

💻

Example

Try this C program yourself

Python
#include <stdio.h>

union Data {
    int number;
    float price;
};

int main() {
    union Data data;

    data.number = 100;

    printf("Number: %d", data.number);

    return 0;
}
📤

Output

Expected result of the program

Output
Number: 100
📝

Practice

Test your understanding

💡

Try it yourself

Don't just read the example. Open your C editor and write the program yourself. Try changing the values and observe what happens.

PRACTICE 01

Modify the example program and experiment with different values.

PRACTICE 02

Write the same program from scratch without looking at the example.

❓

Quick Quiz

Test what you learned

Question 1 of 5Score: 0

What type of language is C?

💼

Interview Questions

Prepare for your C programming interview

1

Interview Question

What is C programming language?

+

Answer

C is a general-purpose programming language widely used for system programming, embedded systems, operating systems and application development.

2

Interview Question

Why is C still important?

+

Answer

C provides efficient low-level memory access and is widely used in systems programming, embedded systems and performance-critical software.

3

Interview Question

What is the purpose of main() in C?

+

Answer

The main() function is the designated entry point of a hosted C program. Program execution begins by calling main().

Chapter 15 of 22

Keep going — you're doing great! 🚀

68%