will be helpful for those in need The output is not strange, it is to be expected: You have three variables in main(), all of which are stored on the stack, and which happen to be right one after the other. One of these variables is the pointer itself. So, when you dereference the pointer in the third line, you get the current value of the pointer itself. Nevertheless, this output is not predictable, it is undefined behavior: You are only allowed to use pointer arithmetic to access data within a single memory object, and in your case, the memory object is just a single int. Consequently, accessing *pa after the first pa++ is illegal, and the program is allowed to do anything from that point on.
This might help you Im reading a book in c++ and I was doing some tests as I didnt understand something and when I tried printing these 3 lines I was expecting something different for all 3. The first one, the location in memory of the pointer, the second one, the address stored by the pointer, and the third one, the value at the address stored by the pointer. But instead the first two were the same: , I dont understand how an arrays name is a pointer to the array
arey An array
&arey Address of the array
f(&arey) Passing the address of the array
f(arey) Still passing the address of the array (ish) - thanks a lot, C!
f(*arey) Passing the first element's value