C program to study typedef keyword
C program for How to use typedef keyword
by Krishna
Posted on 27 Jun 2018 Category: C
Views: 1597
C program to study typedef keyword
typedef is a keyword used in C language to assign alternative names to existing types. Its mostly used with user-defined data types, when names of data types get slightly complicated. Following is the general syntax for using typedef
typedef unsigned char BYTE;
typedef can be used to give a name to user defined data type as well. Let's see its use with structures.
typedef struct
{
type member1;
type member2;
type member3;
} type_name ;
Here is a sample C code that explains how to apply user-defined datatype. Output for the program is also shown below.
#include <stdio.h>
#include <conio.h>
void main()
{
typedef int newtypename;
newtypename x,y,z;
x=50;
y=20;
z=x+y;
printf(“Sum=%d”,z);
getch();
}
OUTPUT