User Defined Datatypes – Typedef

  • It is a keyword, with the help of this we can put another name (alias)  to the existing data type.
  • Syntax :
typedef oldname newname;

Example :

typedef int rollnumber;    //this a valid to compiler
typedef int char;   // this is not valid
  • Here newname should not be a keyword means not known to the compiler.

Example :

#include<conio.h>
#include<stdio.h>
typedef int INTEGER;
main()
{
    INTEGER i;
    printf("%d \n" , sizeof(i));
}


Answer : 
4
  • we can also declare typedef locally.
main()
{
   typedef int CHAR;
   ....
   ....
}

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

Powered by WordPress.com.

Up ↑

%d bloggers like this: