In this method, the declaration starts with typedef followed by key word struct. The data members of the structure are placed between a pair of curly braces after struct. The type name is placed after the closing right brace (}). This is explained in the following example:
typedef struct
{
int datamemberl;
int datamember2;
int datamember3;
} type_name ;
Program provides an illustration of the typedef method where a structure with type-name vector is declared. Any instance of the structure may be declared as given below.
type_name identifier
Illustrates typedef method for declaring structures
# include <stdio.h> typedef struct { int x; int y; int z; } vector; void main () { vector A= {5,8,7}; vector B = {6} ; vector C = {4,8}; clrscr(); printf("A.x = %d \tA.y = %d \tA.z = %d", A.x, A.y, A.z); printf("\nB.x = %d \tB.y = %d \tB.z = %d", B.x, B.y, B.z); printf("\nC.x = %d \tC.y = %d \tC.z = %d", C.x, C.y, C.z); printf ("\n"); }