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
If you want your output to be "43", than you have to change *a++;
to (*a)++;
.
But other than for testing and learning, code like yours is more of a "C thing" than a "C++ thing". C++ offers another approach to referencing data and operating on it, through what the language calls “references”.
int i=42;
int &a=i; // ‘a’ is a reference to ‘i’
a++;
assert(i==43); // Assertion will not fail
References are especially useful for passing arguments to functions, without the risk of having null or displaced pointers.