2 Structures

A structure (struct) in C allows the packaging of related attributes and properties into larger container types. This concept is very important because it is the foundation of structured programming. Structured programming, in return, is the foundation of object-oriented programming.

A simple structure may look like the following:

/* somewhere in x.h or some header file */ 
struct X 
{ 
  int i; 
  char ch; 
  struct 
  { 
    char answer; 
    int score; 
  } c; 
};

In this case, X is the name of the structure. To make variables of this structure, we can use the following declaration:

struct X obj1; /* obj1 is a struct X */  
  

 2.1 Where is each member?
 2.2 Finding out the member offsets
 2.3 Using a structure in assembly language code
  2.3.1 Reserving space as a local variable
  2.3.2 Accessing a member
  2.3.3 Computing the address of a member
  2.3.4 To access a member from a struct pointer
 2.4 Returning a struct