Hi everyone, I'm a noob to C++ and could use some help with understanding one of the practice exercises in "Jumping into C++" by Alex Allain. This is a ch 11 (Structures) quiz question:
“4. What is the final value output by this code? ** Listed Below **
A. 5
B. 10
C. This code will not compile”
The answer is A. 5
What I do not understand is why the updateStruct (my_struct) function containing the my_struct.x value of 10 would not override the existing my_struct.x value of 5 in the main function.
Could someone please explain this to me?
//Receives my_struct by copy. No change inside function
//would affect original value
// ↓↓↓↓↓
void updateStruct (MyStruct my_struct)
updateStruct( my_struct );
// ↑↑↑↑↑
//Copies my_struct. Any changes to it inside function
//would have no effect on it