Variable declaration

There are two ways to declare a structure variable:

  1. At structure definition:

Syntax

struct structName {
    type1 memberName1;  // Members are declared just
    ...                 // like odinary variables
    typen memberNamen;
} variableName1, ..., variableNamen;

Code example

// structure to handle color values
struct rgb {
    int red;
    int green;
    int blue;
} color; // declare color of type rgb
  1. If the structure has already been defined:

Syntax

struct structName variableName1, ..., variableNamen;

Code example

// structure to handle color values
struct rgb {
    int red;
    int green;
    int blue;
}
...
struct rgb color; // declare color of type rgb