0
I have the Following Code:
int main() {
string animal = "cabrito";
string &pn = animal;
pn = "bode";
cout << animal << endl;
return 0;
}
That generates the output:
goat
I was very confused by this code, the address of Pn receives the variable animal and manages to modify it as if it were a pointer, How so?
I also have this code that converts a string to uppercase:
int main() {
string animal = "cabrito";
for (auto &letra: animal) letra = toupper(letra);
cout << animal << endl;
return 0;
}
With the exit:
KID
Basically as in the first code only that changes character by character of the string, I tried to do this but this time with a pointer and it was like this:
int main() {
string animal = "cabrito";
for (auto *letra: &animal) *letra = toupper(*letra);
cout << animal << endl;
return 0;
}
I did it in several other ways using the Pointer but none worked.
After all that code:
string &pn = animal;
pn = "cabrito";
Are you doing?