© Slobodan Dmitrović 2021
S. DmitrovićModern C for Absolute Beginnershttps://doi.org/10.1007/978-1-4842-6643-4_15

15. Structures

Slobodan Dmitrović1  
(1)
Belgrade, Serbia
 

A structure is a type that has members. These members can be variables of other types.

15.1 Introduction

The structure declaration is of the following syntax:
struct some_name
{
      type_name member_name_1;
      type_name member_name_2;
      // ...
};

A structure is also a type. The name of this type is the name of the structure. A structure is a collection of variables, an excellent way to group the variables and organize data.

Let us write a simple example that declares a structure with three members:
#include <stdio.h>
struct MyStruct
{
      char c;
      int x;
      double d;
};
int main(void) ...

Get Modern C for Absolute Beginners: A Friendly Introduction to the C Programming Language now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.