15
I’m writing a feature with the signature: int increment(int *val)
. My intention is to receive an entire pointer, increase 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.
Because when using the unary operator does it modify the memory address? Theoretically it was not meant to amount to *val += 1
? Thank you if there are examples explaining.