Example & Tutorial understanding programming in easy ways.

What is typedef in C++?

What is typedef in C++ ?
-The typedef keyword allows the programmer to create new names for types such as int or, more commonly in C++,
-C++ allows you to define explicitly new data type names by using the keyword typedef.
-Using typedef doest not actually create a new data class, rather it defines a new name for an existing type. This can increase the portability of a programas only the typedef statements would have to be changed.

Syntax-
typedef type name;

program:

#include < iostream>
using namespace std;
int main()
{
typedef int integer;
integer n1,n2,sum;
cout<<"Enter two numbersn";
cin>>n1>>n2;
sum=n1+n2;
cout<<"Sum is: "<< sum;
return 0;
}


output-

Enter two number
34
Sum is: 36

-In this program, we changed the int to integer. so that we can initialize the integer number through integer instead of int.




Read More →