The increment value int is indicated by a pointer

I have an int pointer (i.e. int *count ) that I want to increment the integer that the ++ operator points to. I thought I would call:

 *count++; 

However, I get a warning about the assembly "expression result is not used." I can call

 *count += 1; 

But I would like to know how to use the ++ operator. Any ideas?

+65
c increment pointers post-increment
Sep 07 '10 at 4:16
source share
2 answers

++ has equal priority with *, and associativity from right to left. See here. This made it even more difficult because although ++ would be bound to a pointer, the increment is applied after evaluating the operator.

Case of things:

  • Incremental increment, remember the value of the address of the pointer after increasing as a temporary
  • Indication of a non-incremental pointer to a pointer
  • Apply the pointer address of the pointer for counting, counting now points to the next possible memory address for an object of its type.

You get a warning because in step 2 you never use the dereferenced value. Like @Sidarth, you will need a bracket to force the evaluation order:

  (*ptr)++ 
+86
Sep 07 '10 at 4:23
source share

Try using (*count)++ . *count++ can increment the pointer to the next position, and then use indirect (which is unintentional).

+14
07 Sep '10 at 4:19
source share



All Articles