auto vs. auto& vs. auto&& vs. auto const & | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

auto vs. auto& vs. auto&& vs. auto const &

I am pretty new to C++ and programming in general. I came across the auto keyword while learning about the different containers and how to use iterators to access each element of the container. After some research, I figured out that I could simplify the statement in the loop into auto& it : myMap compared to its much longer variant. I did some more research and found that there was also auto&& and auto const &. Can someone give a clear explanation on the difference between all four?

17th Jul 2018, 3:36 AM
Justin Lam
Justin Lam - avatar
2 Answers
0
I would say that here is the good explanation: https://stackoverflow.com/questions/29859796/c-auto-vs-auto
17th Jul 2018, 5:11 AM
Highman
Highman - avatar
0
I am beginning to understand all but the auto&&. What is the difference between that and auto&?
17th Jul 2018, 6:00 AM
Justin Lam
Justin Lam - avatar