On 5/29/07, sanjib kumar ghorui <[EMAIL PROTECTED]> wrote:
>
>   Hi,
>
>   How do we print the static 'a' within the scope(where the printf is
> called,)


You can't in C. The opening brace of the inner block and the subsequent
declaration of a new a hides the previous version. The same applies to
accessing the global a from within the function fun().

The only way round it is change the name of the inner versions of the
variable.

In C++ you have the :: operator which may help (Google for [scope resolution
C++])

  #include<stdio.h>
>   #include<stdlib.h>
>
>   int a=1;
>   void fun(void)
>   {
>   static int a=2;
>   {
>   int a =3;
>   printf("%d %d ",a, ::a);
>   // here we have to print the static a
>   }
>   }
>   void main()
>   {
>   fun();
>
>   }
>


-- 
PJH
"I contend that we are both atheists. I just believe in one fewer god than
you do. When you understand why you dismiss all the other possible gods, you
will understand why I dismiss yours."
-- Stephen Roberts


[Non-text portions of this message have been removed]

Reply via email to