so I am a beginner pretty much but I stumbled on something confusing to me.
int* p = new int[3];
//Now I want to increment the Pointer and add value 10 there.
int* n = new int[3];
std::cout << n << std::endl;
*n++=10;
std::cout << n << " :: " << *n << std::endl;
return 0;
However, what gets printed on the second std::cout @ * n is zero and not the expected 10. The pointer address seem to have increased by 4 bytes successfully but not the value. What am I doing wrong? Doing the same with *n+1 = 10; works like intended.
int main()
{
int* n = new int[3];
std::cout << n << std::endl;
*(n+1)=10;
std::cout << n << " :: " << *(n+1) << std::endl;
return 0;
}
I also noticed that outputting following
int main()
{
int* n = new int[3];
std::cout << n <<"::"<< n++ ;
}
now on the n++ print, I would expect the hex value to have increased by 4, however it actually decreased by 4. Why is that? I expected it to be 4 larger than n but n++ is 4 smaller. If i do n-- the address seems to get larger? I am really confused