Incrementing pointer not working

前端 未结 5 1891
后悔当初
后悔当初 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 03:03

    You have used *a++;

    As your increment operator ++ has higher precedence than your pointer *, what actually is happening is that your pointer address is being incremented. So the new *a has no defined value and hence it will give an undefined value *a++; is the equivalent of a++;

    To fix this you can use parentheses (*a)++; or simply us pre increment operator ++*a;

提交回复
热议问题