CHAPTER 2

image

Structures

In this chapter, we will explain the following:

  • What a structure is
  • How to declare a structure
  • How to use typedef to work with structures more conveniently
  • How to work with an array of structures
  • How to search an array of structures
  • How to sort an array of structures
  • How to declare nested structures
  • How to use structures to manipulate fractions
  • How to use structures to solve a “voting” problem
  • How structures can be passed to a function

2.1 Defining Structures

In C, a structure is a collection of one or more variables, possibly of different types, grouped together under a single name for convenient handling.

There are many ...

Get Advanced Topics in C: Core Concepts in Data Structures now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.