Using typedef in C Language

The typedef keyword creates a type definition that simplifies code and makes a program easier to read.

typedef is commonly used with structures because it eliminates the need to use the keyword struct when declaring variables.

Declaring typedef in Structure

1

2

3

4

5

6

7

8

9

typedefstruct

{

floatprice;

charname[50];

intpages;

}book;

book b1;

book b2;

Note that, a structure tag is no longer used, instead a typedef name appears after the struct declaration. Now the word struct is no longer required in variable declarations, making the code cleaner and easier to read.