sushant said:
thnx a tonne alex but can you explain me why on reversing the order of
declaration of x and *p it is giving the same o/p when we replace that
statement with another one ?
Please read again and carefully consider what Alex wrote.
There's absolutely no reason to expect the address values
output to be anywhere near one another. They're *two
separate programs*. And e.g. a 'virtual memory' system
might (and often does) move things around so that subsequent
invocations of the exact same program could give different outputs.
The only consistent outputs you should expect are of those specific
values you assign to your objects. In the case of addresses, that's
why we must use 'pointer = &object' syntax instead of
'pointer == some_literal_value'. '&object' means 'address of object',
*wherever that may happen to be*. The only time you can expect
(actually you're guaranteed) that a pointer will retain its value is
during the current execution of the scope where its value was initialized
or assigned. (But note the exception that if the pointer was given its value
from 'malloc()' or 'realloc()', a call to 'free()' with that same value as
its argument releases the language from that guarantee.
BTW please stop top-posting to comp.lang.c.
Thank you.
-Mike