Summary

  • A structure is a collection of one or more variables, possibly of different types, grouped together for convenient handling.
  • Structures help to organize data because they allow a group of variables to be treated as a single unit.
  • A structure declaration starts with the keyword struct, which introduces the declaration.
  • The structure tag, which follows the keyword, is optional. It is only a label and not an actual structure in memory.
  • The declaration then follows with a list of variables enclosed within curly braces. These variables are called members.
  • Members can be accessed using the member access operator '.".
  • The struct declaration defines a new datatype.
  • Nested structures are nothing but structures within structures.
  • The 'typedef" statement is used to define a new datatype.
  • Pointers to structures are just like pointers to other variables.
  • Members can be accessed through the pointer variable using the member access operator '- >".
  • Structures may be passed to functions either by value or by reference.
  • A union is a variable that may hold objects of different types at different times.
  • A union declaration is similar to a structure declaration.