Incrementing pointer not working

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

    Your code works fine till you reach the line

    *a++;
    

    As you know, C++ compiler will break this code of line as

    *a = *(a+1);
    

    That is, it will first increment address value of a and then assign the value to *a. But if you do,

    *(a)++;
    

    then you will get correct output, that is, 43.

    For output- http://ideone.com/QFBjTZ

提交回复
热议问题