#include<stdio.h> int main() { int = 10; int *p = &a; int b = 800; double d=547; int c=900; printf("a = %d\n", a); printf("p = %p\n", p); printf("*p= %d\n", *p); p++; //p = &b; printf("a = %d\n", a); printf("p = %p\n", p); printf("*p= %d\n", *p); return 0; }
if print value stored in p after increment why i'm getting 900 instead of 800?
[1]:strong text http://i.stack.imgur.com/hyrla.png
besides people have said (undefined behavior), reason lie in rearrangement of code compiler.
according standard,nothing forbids compiler rearrange order of code, long values of variables remain same, possible variables rearranged in such way going 1 int forward points variable c.
but not part of standard, there no way of knowing happen, , different compilers may return different results code.
Comments
Post a Comment