Structure and union variable declarations

A structure or union declaration has the same form as a definition except the declaration does not have a brace-enclosed list of members. You must declare the structure or union data type before you can define a variable having that type.

Read syntax diagramSkip visual syntax diagramStructure or union variable declaration syntax
 
   .-----------------------------.
   V                             |
>>---+-------------------------+-+--+-struct-+------------------>
     +-storage_class_specifier-+    '-union--'
     '-type_qualifier----------'
 
>--tag_identifier--declarator--;-------------------------------><
 

The tag_identifier indicates the previously-defined data type of the structure or union.

C++ The keyword struct is optional in structure variable declarations.

You can declare structures or unions having any storage class. The storage class specifier and any type qualifiers for the variable must appear at the beginning of the statement. Structures or unions declared with the register storage class specifier are treated as automatic variables.

The following example defines structure type address:

struct address {
    int street_no;
    char *street_name;
    char *city;
    char *prov;
    char *postal_code;
    };
     

The following examples declare two structure variables of type address:

struct address perm_address;
struct address temp_address;      

Related information



[ Top of Page | Previous Page | Next Page | Contents | Index ]