I have an int
pointer (i.e., int *count
) that I want to increment the integer being pointed at by using the ++
operator. I thought I w
Try using (*count)++
. *count++
might be incrementing the pointer to next position and then using indirection (which is unintentional).
The ++ has equal precedence with the * and the associativity is right-to-left. See here. It's made even more complex because even though the ++ will be associated with the pointer the increment is applied after the statement's evaluation.
The order things happen is:
You get the warning because you never actually use the dereferenced value at step 2. Like @Sidarth says, you'll need parenthesis to force the order of evaluation:
(*ptr)++