Changing a Local Variable With a Different Function [duplicate]
Solution 1:
The problem is that you declared the function increaseNumber
in such a way that the parameter is passed by value:
void increaseNumber( int64_t number )
That way, it is passed a copy of the value of the variable number
of the function get_number
. Therefore, modifying the variable number
of the function increaseNumber
will not change the variable number
of the function get_number
, as these are two separate variables.
If you instead want the original variable's value to be modified too, then you should not pass a copy of the variable's value, but you should instead declare the function in such a way that a reference to the original variable is passed:
void increaseNumber( int64_t& number )
That way, no copy of the original variable will be made, and your program should work as intended, without any further modifications being necessary.
The reason why using an array worked with you is that if you pass an array, it will decay to a pointer, which is equivalent to a reference.