+ 1

what's the use of auto in C++?

13th Apr 2018, 2:56 PM
Subhrajyoti Bhowmick
Subhrajyoti Bhowmick - avatar
2 Antworten
+ 3
It automatically detect type of variable. For example: auto x = 1; generates int variable It is useful for foreach loops in C++11 when we doesn't know what type of variable has vector.: std::vector<int> v(10, 0); for (auto i : v) std::cout << i;
13th Apr 2018, 3:24 PM
Bartosz Pieszko
Bartosz Pieszko - avatar
+ 2
If you don't care about the type or it's obvious, use auto.
13th Apr 2018, 3:37 PM
Timon Paßlick