About this document
C Union Basics with Examples by Harshit Naik is a document available to read on EtoBox.
Unions in C allow storing different data types in the same memory location. Only one member can be accessed at a time. Structures allocate space for all members, while unions allocate space for the largest member only. To define a union, the union keyword is used followed by member variables. Union variables are then created to allocate memory and access members using dot or arrow operators. The size of a union is the size of its largest member, while a struct size is the total size of all members.
- Author
- Harshit Naik
- Language
- EN