On 30 Dec 2006 08:09:01 -0800, "Abhi" <ab*************@gmail.com>
wrote:
>Referring to the post given by MR herald,
Which you should have quoted to provide some context.
>If the statements
Small nit. The two lines of code below are not statements but
declarations (that also serve as definitions).
>
int *ap = &a;
static int a = 10;
are reversed, wont the results for a be the same.. I think this answer
For each a - yes. But not for ap.
>should be given independent of the order in which the declarations are
But the standard states that the scope of an identifier begins just
after the declaration. Therefore order is important.
In the code as posted, at the time the pointer is initialized, the
only a in scope is the one (not shown) declared at file scope. This a
is not hidden by the a at block scope until the scope of that
identifier begins. Therefore, the only value available to be assigned
to ap is the address of the a at file scope.
However, if you reverse the declarations, by the time you declare the
pointer, the scope of the block a will have begun (resulting in the a
at file scope being hidden). Therefore, the only value available to
be assigned to ap is the address of the a at block scope.
>done and I think the right way of doing it is by using the function to
access it as global.
Remove del for email