P
Patrick6
Hello everyone,
I found something weird happening with a pointer:
Take the following code:
int x=0, n=10, *px=&x, *py=NULL;
printf ("BEFORE: valeur de px = %p et py = %p\n\n", px, py);
*px++=n;
printf ("AFTER : valeur de px = %p et py = %p \n", px, py);
It gives the following result, quite clear, with px becoming px+1 :
BEFORE: valeur de px = 0012FF78 et py = 00000000
AFTER : valeur de px = 0012FF7C et py = 00000000
Everything will stay that way (I mean, normal), should I replace
*px++=n by anything that crosses my mind, like:
*px++; or *++px; (!) or simply px++; or ++px;
But if I do: *++px=n instead, I get the amazing output:
BEFORE: valeur de px = 0012FF78 et py = 00000000
AFTER : valeur de px = 0012FF7C et py = 0000000A <====== (here)
where the value of the py pointer (which has nothing to do with px in
the first place!) has changed.
What is this?
Anyone having any opinion will be quite welcomed, except to say that I
am like the pointer py.
Compiler Microsoft C++ Visual Studio 97 under W2K.
I found something weird happening with a pointer:
Take the following code:
int x=0, n=10, *px=&x, *py=NULL;
printf ("BEFORE: valeur de px = %p et py = %p\n\n", px, py);
*px++=n;
printf ("AFTER : valeur de px = %p et py = %p \n", px, py);
It gives the following result, quite clear, with px becoming px+1 :
BEFORE: valeur de px = 0012FF78 et py = 00000000
AFTER : valeur de px = 0012FF7C et py = 00000000
Everything will stay that way (I mean, normal), should I replace
*px++=n by anything that crosses my mind, like:
*px++; or *++px; (!) or simply px++; or ++px;
But if I do: *++px=n instead, I get the amazing output:
BEFORE: valeur de px = 0012FF78 et py = 00000000
AFTER : valeur de px = 0012FF7C et py = 0000000A <====== (here)
where the value of the py pointer (which has nothing to do with px in
the first place!) has changed.
What is this?
Anyone having any opinion will be quite welcomed, except to say that I
am like the pointer py.
Compiler Microsoft C++ Visual Studio 97 under W2K.