I was reading about "range for
" statements when I got confused how it exactly works.
Below is a program to convert a string to Uppercase.
string s("Hello World!!!");
//convert s to uppercase
for( auto &c :s ) // for every char in s
c= topper(c); // c is a reference,so the assignment changes the
// char in s
cout<< s << endl;
How is the reference to the string (that is, c
) is changing elements to upppercase?
I've searched about how iteration could work here, but I couldn't find the answer.