Unions
Last updated
What is Unions?
A union allows multiple members to share the same memory location, so only one member holds a valid value at any given time, and the union's size equals that of its largest member. This is useful for saving memory when different pieces of data are never needed simultaneously, or for interpreting the same bytes in different ways. Reading a union member other than the one most recently written to is generally undefined behavior, except in specific cases the standard permits.
Free resources to learn Unions
- ArticleUnions in C
- ArticleUnion declaration
- VideoIntroduction to Unions in C
More in stage 11: User-Defined Types
Unions: common questions
Can I learn Unions in Hindi?
This lesson is written in English. Once you sign in, open it in the interactive course and ask the AI tutor to explain Unions in Hindi or Hinglish. The tutor answers from this lesson’s own text, so it stays on the syllabus, and it runs on your own Google, OpenAI or Anthropic key.
Is this Unions tutorial for beginners?
It is lesson 54 of 141 in the free C Programming roadmap, in stage 11, User-Defined Types. If you are new to C Programming, start from stage 1 and come back here in order; if you already know the earlier stages, this lesson stands on its own.