I am writing a function with the signature: int increment(int *val)
. My intention is to get an integer pointer, increment its value in 1 and return that value.
The body of my function was as follows:
int increment(int *val)
{
*val += 1; // Dessa maneira o valor de val é incrementado em 1.
return *val;
}
In the commented line, when I used the unary operator ++
, as in *val++;
I received the changed memory address.
Why does using the unary operator modify the memory address? Theoretically it was not meant to be equal to *val += 1
? Thanks for any examples.