C Programming - SPLessons

C Typedef

Chapter 29

SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

C Typedef

C Typedef

shape Description

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.

shape Syntax

typedef original_name  alternate_name;

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

shape Example

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


Storage size for lli type: 8

shape Advantages

Typedef in functions

shape Description

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.

shape Example

#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


shape Key Points

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

shape Programming

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