Why does the below two snippets of code have different results? I want to add a 1 in front of digits, which is a vector of integers. But the second snippet does not properly swap.
int tmpInt(1); for (int i=0; i<digits.size(); i++){ swap(tmpInt, digits[i]); } digits.push_back(tmpInt); versus:
int tmpInt(1); for (auto it : digits){ swap(tmpInt, it); } digits.push_back(tmpInt);
int x = 6; int y = x; y = 4; // why is x still 6 instead of 4????