How to print value of global variable and local variable having same name?

Use the extern specifier in a new compound statement.

This way:

#include <stdio.h>      

int a = 12;             

int main(void)          
{           
    int a = 15;             
    printf("Inside a's main local a = : %d\n", a);

    {
        extern int a;
        printf("In a global a = %d\n", a);
    }

    return 0; 
}

Leave a Comment