What is the precedence when there is a Global variable and a Local variable in the program with the same name? | SoloLearn: Learn to code for FREE!

+1

What is the precedence when there is a Global variable and a Local variable in the program with the same name?

2/2/2020 12:45:03 PM

kaustubh purohit

1 Answer

New Answer

+1

When the global and the local variable have the same name : 1. Local variable is taken in the local scope where it is defined. 2. Outside the local scope the global is used. So if we have #include<stdio.h> int x = 5; int main(){ int x = 10; printf("x is : ",x); return 0; } // This code here prints 10