typedef in C++ by R4R Team

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 programs 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.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!