using auto to declare datatypes

Hi community

This post explains the use of auto which can save lot of time during programming contest.

When a variable is defined as auto, compiler determines its type during compile-time. This is because when a new variable is initialized, the compiler can figure out what the type of the variable is automatically by the initializer. For this, it suffices to use auto as the type specifier for the variable: For example,

auto a = 1; // a will become 'int'
auto b = 1LL; // b will become 'long long'
auto c = 1.0; // c will become 'double'
auto d = "variable"; // d will become 'string'

Happy Coding …

N.B. These are C++11 and above features, which is supported by all major online judges. Will not work for earlier versions.

To know more use this site link text

I think you should also mention that auto keyword works only in C++11 and C++14.

I have tagged c++. Anyway thanks for suggesting , will mention it.

The auto keyword is a declaration specifier. However, the C++ standard defines an original and a revised meaning for this keyword.Go to best essay writing services If you have any doubt regarding writing essays on this topic.

Why is best essay writing services mentioned here?

one classic example where auto can be used is : iterators ;
In stl while looping over different containers iterators are used and that is where auto declaration is most effective

For example :

vector<int> x;

for(vector<int>::iterator it=x.begin();it!=x.end();it++)
cout<<(*it);

can be replaced with

for(auto it=x.begin();it!=x.end();it++)
cout<<(*it);
2 Likes