typedef datatypes in C++

How are typedef datatypes used in C++?
How to give an alternate name for an existing datatype?


Alternate data type names are defined using the keyword "typedef" for the existing datatypes. This is used to make the code more portable, as the data type can be changed using a single "typedef" statement.


typedef type newname;

Example :

#include typedef int AGE; void main()
AGE i;
cout << "Enter your age::" << endl;
cin >> i;
cout << "Your age is::" << i << endl;

Result :

Enter your age::
Your age is::23

In the above example typedef keyword is used to give an alternate name to "int" datatype as "AGE".

C++ Tutorial

Ask Questions

Ask Question