Abstract
The union type is identical to the struct type, except that all fields share the same memory position. Therefore, the size of a union is the size of the largest field it contains. In the following code, this is the integer field, which is four bytes.
union mix { char c; /* 1 byte */ short s; /* 2 bytes */ int i; /* 4 bytes */ };
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Author information
Authors and Affiliations
Rights and permissions
Copyright information
© 2019 Mikael Olsson
About this chapter
Cite this chapter
Olsson, M. (2019). Unions. In: Modern C Quick Syntax Reference. Apress, Berkeley, CA. https://doi.org/10.1007/978-1-4842-4288-9_14
Download citation
DOI: https://doi.org/10.1007/978-1-4842-4288-9_14
Published:
Publisher Name: Apress, Berkeley, CA
Print ISBN: 978-1-4842-4287-2
Online ISBN: 978-1-4842-4288-9
eBook Packages: Professional and Applied ComputingProfessional and Applied Computing (R0)Apress Access Books