UncleCoder.com

UncleCoder.com

Free programming examples and instructions

C program to study typedef keyword

C program to study typedef keyword

by Krishna viswambharan


Posted on 31 Oct 2017 Category: C Views: 82

Edited on 02 Jul 2018


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



Leave a Comment:


Advertisement