by Dinesh Thakur Category: Structure And Union

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};
  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");

Typedef in Structure Declaration in C

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.