auto keyword in C++ by R4R Team

Auto keyword:
-Here auto refers as automatically.
-The auto keyword specifies that the type of the variable that is being declared will be automatically deducted from its initializer.
-auto becomes int type if even an integer reference is assigned to it

program:

#include < iostream>
using namespace std;
int main()
{
//Here i is automatically integer number
auto i=10;
//Here f is autommatically float number
auto f=4.1;
cout<<"Value of i is: "<< i<< endl;
cout<<"Value of j is: "<< f;
return 0;
}


output-

Value of i is: 10
Value of j is: 4.1

-In this program, the data_type of the variable is automatically decided by the compiler due to the auto keyword.




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!