"pointer++" and "pointer + 1" VStudio 2010

Hi All,

I've just started using Visual Studio 2010 beta and I have noticed something strange: if I increase a pointer using "pointer++" and then display the memory address, I notice that the new address is LESS than the previous by as many bits as the type requires.
If, instead, I display the pointer without changing it by using, for example "cout << pointer + 1", then, as expected the memory address is increased by as many bits as it should.
Example with int*:
in the first case
001AFA5C becomes 001AFA58 (so it's 4 bits less)
in the second case
001BFA58 becomes 001BFA5C (so, as expected it's 4 bits more)
The very opposite happens using "pointer--", the memory address is increased by 4 bits.

Any clue on why this might happen?

Cheers

P
weird
Works as expected for me on VC++ 2008.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>

int main(){
	int a[]={4,7,3};
	int *b=a+1;
	std::cout <<b<<std::endl;
	std::cout <<*b<<std::endl;
	b--;
	std::cout <<b<<std::endl;
	std::cout <<*b<<std::endl;
	b=a+1;
	b++;
	std::cout <<b<<std::endl;
	std::cout <<*b<<std::endl;
	return 0;
}

I'm not prepared to believe that two versions of the same compiler two years apart would vary so wildly.
your code works as expected with VC++ 2010 too. I must have been doing something wrong with the intialization. Weird output though.
thanks
Topic archived. No new replies allowed.