As in the for loop of the following code, why do we have to use reference (&c
) to change the values of c
. Why can't we just use c
in the for
loop.
Maybe it's about the the difference between argument and parameter?
#include "stdafx.h"
#include<iostream>
#include<string>
using std::string;
using std::cout;
using std::cin;
using std::endl;
int main()
{
string s1("Hello");
for (auto &c : s1)
c = toupper(c);
cout << s1 << endl;
return 0;
}