Home : C Language : Variables : Structures
Structure declarations are of the form:
- [attributes]
struct[struct_name]{- type
element_name;- type
element_name;- type
element_name;}[var_name,var_name];
where the optional var_names are variables declared to be of this structure type, and the optional struct_name is a name for this structure type which may be used in subsequent variable declarations of the form:
[attributes]
structstruct_namevar_name;
var_name refers to the contents of the entire structure. Hence a structure may be passed to a function, and structure assignments are allowed:
var_name
=var_name;
The variables should have the same number and type of elements, but don't have to be declared as identical structure types.
An element within a structure is referred to using:
var_name
.element_name
A pointer to a structure is declared using:
structstruct_name*var_name;
If the address of a structure of type struct_name is then assigned to var_name, then the contents of this entire structure is referred to using:
*var_name
However, an element within this structure is referred to using:
var_name
->element_name
Arrays and structures may be nested to several levels.