typedef data type

By typedef type data type, we can display any data type, by different name that is, an identifier can be displayed from the data type,

Such as,

typedef-keyword

Remember here the name of the data type is being changed, rather than creating a new data type, that means it used to represent a already declared data type name rather creating new data type.

SYNTEX:-

typedef data-type indentifier;

How to use typedef data-type in a program?

firstly, we declare a identifier as data-type in a single statement such as,

typedef int number;

Now, number behave like an int data-type,

number x=10;

Let’s try this an example here,

Example:-
As we already know, the int type data type stores the digit value but here we define number as int with the help of typdef. now number behave like a int data type.

#include<iostream.h>
#include<conio.h>

 void main()
  {
    typedef int number;

    number x=10,y; // x variable assign 10 and y declare

    clrscr();
 
    cout<<"Enter Number: ";
    cin>>y;

    cout<<x<<" "<<y; // print both variable value

    getch();
 }
OUTPUT:-
Enter Number: 10 20

Similarly, you can also use typedef data type with other data type (char, float).

Here is another Example of typedef where we create a loading bar with the help of array.


previousenumereated data type in C++

next-Data type and their type in C++