Pointer incrementing query
Posted
by Craig
on Stack Overflow
See other posts from Stack Overflow
or by Craig
Published on 2010-03-07T07:41:31Z
Indexed on
2010/04/07
15:03 UTC
Read the original article
Hit count: 291
I have been looking at this piece of code, and it is not doing what I expect.
I have 3 globals.
int x, y, *pointer, z;
Inside of main I declare them.
x = 10;
y = 25;
pointer = &x;
now at this point
&x is 0x004A144
&y is 0x004A138
pointer is pointing to 0x004A144
Now when I increment:
y = *++pointer;
it points to 0x004A148, this is the address y should be at shouldn't it?
The idea is that incrementing the pointer to 'x' should increment it to point
at y, but it doesn't seem to want to declare them in in order like I expect.
If this a VS2005 / 2008 problem? Or maybe an Express problem?
This isn't really homework, as I have done it a couple of years ago but I was revising on my pointer stuff and I tried this again. But this time I am getting unexpected results. Does anyone have opinions on this?
*UPDATE
sorry should be more clear, 'thought' on declaration 'y' should be at 148, and that incrementing the pointer pointing to x should increment 'pointer' to 148 (which it does), but that isn't where y is. Why isn't y declaring where it should be.
© Stack Overflow or respective owner