previous | start | next

Structures

The following statement defines a type

struct S1 {
  char c1;
  int n;
  char c2;
  double x;
};

Variables can then be defined of this struct type:

  struct S1 s; /* Ugh! */      
   

and members can be referenced and assigned values:

 s.c1 = 'A';
 s.n = 42;
 s.c2 = s.c1;
 s.x = 2.7;
   

S1 is called the structure tag.

The "name" of the type is struct S1, not just S1.

So it is an error to define a variable like this:

 S1 s; /* ERROR */
   


previous | start | next