The C programming language provides a keyword called typedef . We can use typedef to give new name to a data type or we can that It is used to create a synonymous. Following is an example to define a term BYTE for one-byte numbers. After this type definitions, the identifier BYTE can be used as an abbreviation (short name) for the type unsigned char, for example typedef unsigned char BYTE ; BYTE b1, b2;
By convention, uppercase letters are used for these definitions to remind the user that the type name is really a symbolic abbreviation, but you can use lowercase, as follows: You can use typedef to give a name to user defined data type as well. For example you can use typedef with structure to define a new data type and then use that data type to define structure variables directly as follows:- typedef unsigned char byte ;
#include <stdio.h> typedef struct Emp { char Name[20]; char DOJ[11]; int ID; int Salary; } Emp; int main( ) { Emp E; printf("Enter the Name:-"); scanf("%[^\n]s",E.Name); printf("Enter the DOJ:-"); scanf("%s",E.DOJ); printf("Enter the ID:-"); scanf("%d",&E.ID); printf("Enter the Salary:-"); scanf("%d",&E.Salary); printf("---------------------------"); printf("\nThe Name:%s\nThe Date of Joing:%s\nThe ID is: %d\ nThe Salary is: % d",E.Name,E.DOJ,E.ID,E.Salary ); }
When the above code is compiled and executed, it produces the following result:- Enter the Name:-Ayaan Khan Enter the DOJ:-10/09/2000 Enter the ID:-4522 Enter the Salary:-50000 --------------------------- The Name:Ayaan Khan The Date of Joing:10/09/2000 The ID is:4522 The Salary is:50000 INPUT OUTPUT
note:- These identity won’t occupy any memory in application. We can declare these variable either locally or globally. Thank You