C - SPLessons

Chapter 29

C Typedef

C Typedef

C Typedef is nothing but “Type-Definition“.

C Typedef is used to give alternative names to the original names to reduce the complexity of the program. They acts as “alias names” or “shorthand versions” of structure names/data-types.

typedef original_name  alternate_name;

typedef int number;
number x=10; //number really means int

int main()
	typedef long long int lli;
	printf("Storage size for lli type: %ld", sizeof(lli));
	return 0;


Storage size for lli type: 8

Typedef in functions

To declare a name to which already C typedef exists, that name should consists of a type-specifier to avoid confusion. If want to use typedef with function, specify only the return value not all the parameters of the function.

#include <stdio.h>
#include <string.h>

typedef struct student 
  int id;
  char name[20];
  float percentage;
} status;

int main() 
  status record;
  strcpy(record.name, "James");
  record.percentage = 86.5;
  printf(" Id is: %d \n", record.id);
  printf(" Name is: %s \n", record.name);
  printf(" Percentage is: %f \n", record.percentage);
  return 0;


Id is: 1
Name is: James
Percentage is: 86.500000


  • C Typedef gives user-defined data types.
  • All data types defined will be under the control of compiler.

Declarations must be clear to avoid confusion between two alias names.