"typedef" keyword gives user an unique flexibility to define a new type for existing types. This is mainly a creating a new named alias for existing types or user defined types.

typedef <old type name> <new type name>;

typedef unsigned char UINT8;
typedef unsigned int UINT32;

typedef struct student_ {
  char * name;
  int roll;
} student_t;

struct student_ {
  char * name;
  int roll;
typedef struct student_  student_t;

Now one question may arise here is if we already have a type why to define a new type name as both are same and serves same purpose. Answer is we get some advantages here and they are-

  1. Typedef can reduce long type names to more meaningful and shorter names.
  2. This new name gives more readability and maintainability to the code.
  3. Defining an architecture independent type of like UINT32 (Typedef unsigned int UINT32;) and using this across the code base ensures that code can be ported easily to any architecture or platform.

About our authors: Team EQA

You have viewed 1 page out of 252. Your C learning is 0.00% complete. Login to check your learning progress.