Global and local name collision

Given the following source code

static int a_static_var = 5;
void foo(void)
    static int a_static_var = 6;


How your compiler will differentiate between global and local variable when they have same name.However answer to this question is compiler dependent but you can give your answer according to compiler you use.


  1. In C++, using the scope resolution operator ::

    In C, conflict is resolved in favour of local variable always.

  2. @jainendra but if you want to use global variable somewhere outside foo() ,then how compiler differentiate between them.Basically this is resolved using name mangling..


Post a Comment

Popular posts from this blog