C++ references

0 Alekro A · September 1, 2014
Hello everyone!
I am reading the book c++ primer (5th edition) and i just dont understand why c in this code has to be a reference :


 string s("Hello World!!!"); 
for (auto &c : s)   // here c is a reference
 c = toupper(c);
cout << s << endl;

The output of this code is HELLO WORLD!!

Could someone plz explain it to me in an understandable way.

Thank you very much!

Post a Reply

Replies

Oldest  Newest  Rating
0 Alekro A · September 4, 2014
GESU YOUR A GENIUS! Thx man i understand now!
  • 1

C++

107,151 followers
About

Used in many types of software including music players, video games, and many large scale applications.

Links
Moderators
Bucky Roberts Administrator