Structure Union
Structure stores each member in a sequence of order in the memory. Union stores members in overlapping memory where starting
C structure, members, size C union, members, size
structure has a size which is sum of individual member union has has the same size as the maximum size of an member
Syntax:
struct <name> {
  <type> <member name 1>;
  <type> <member name 2>;
  ...
  <type> <<member name N>;
};
Syntax:
union <name> {
  <type> <member name 1>;
  <type> <member name 2>;
  ...
  <type> <member name N>;
};
Individual member of structure can be accessed independently and writing a new value will not affect other members. Individual member of union cannot be accessed independently, modifying a member can result in modifing the values of other members

You have viewed 1 page out of 248. Your C learning is 0.00% complete. Login to check your learning progress.

 Vote 0

Similar topics related to this section

user defined types, typedef, struct type, union type, struct vs union, struct pack padding, size of a structure, bit fields, l-value, struct and array,

# C Programming Language (Prentice Hall Software)
# Let Us C Paperback - 2006 by Yashavant Kanetkar
# Understanding and Using C Pointers Core techniques for memory management
# Data Structures Using C and C++ Paperback - 1998
# Data Structures In C Paperback - August 11, 2008 by Noel Kalicharan