typedef Data Type in C++

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

Such as,


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.


typedef data-type identifier;

How to use typedef data-type in a C++ 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,

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.


 void main()
    typedef int number;

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

    cout<<"Enter Number: ";

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

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++