"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.

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

 Vote 0

Similar topics related to this section

LCM, Pascals triangle, user defined types, typedef, struct type, union type, struct vs union, struct pack padding,

# C Programming Language (Prentice Hall Software)
# Let Us C Paperback - 2006 by Yashavant Kanetkar
# Understanding and Using C Pointers Core techniques for memory management
# Data Structures Using C and C++ Paperback - 1998
# Data Structures In C Paperback - August 11, 2008 by Noel Kalicharan