Incrementing pointer not working

前端 未结 5 1889
后悔当初
后悔当初 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条回答
  •  -上瘾入骨i
    2021-01-24 02:54

    ++ has a higher operator precedence than the pointer dereference operator *.

    So what *a++ does is to return the value of i (the old value of *a) before incrementing the pointer value.

    After that expression has been evaluated, a now points to something other than the address of i, and the behaviour of a subsequent *a is undefined.

    If you want to increment i via the pointer, then use (*a)++;

提交回复
热议问题