Incrementing pointer not working

前端 未结 5 1890
后悔当初
后悔当初 2021-01-24 02:30

I’m trying to increment pointer. I was sure that it is similar to do i+=1 , but I’m getting adress.

#include \"stdafx.h\" 
#include          


        
5条回答
  •  遥遥无期
    2021-01-24 02:56

    What does "I'm getting adress" mean?

    Have you checked out order of operations?

    http://en.cppreference.com/w/cpp/language/operator_precedence

    ++-postfix is a higher precedence than *-dereference - hence:

    *a++;
    

    is really:

    *(a++);
    

    and not:

    (*a)++;
    

    ... as you probably meant. Which is IMHO why I always recommend erring on the side of too many parentheses rather than too few. Be explicit as to what you mean :)

提交回复
热议问题