#1 India's Top IT Training Institute

×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
Data Structures

Difference Between Structure and Union in C Language

What is a Structure?

A struct groups variables of different data types under one name, with each member having its own memory space.

struct Student {
    int id;
    char name[20];
};

What is a Union?

A union also groups variables of different data types under one name, but all members share the same memory location.

union Data {
    int i;
    float f;
};

Key Differences

  • Memory: struct allocates separate memory for each member; union allocates memory equal to its largest member, shared by all.
  • Access: in a struct, all members can hold valid values simultaneously; in a union, only one member holds a valid value at a time.
  • Size: sizeof(struct) is the sum of all members' sizes (plus padding); sizeof(union) equals its largest member's size.

Ready to master real-world C Programming development?

Learn C Programming hands-on with mentor-led, live sessions.

Explore Course