somy question is, **Is there two variable named x in the main ,one goes to g() with value 1 go there prints 2 and another one keeps at 1 again prints 2 in main. **
#include <stdio.h>
void f(){
extern int x;
x++;
printf("%d",x);
}
int x;
void g(){
++x;
printf("%d",x);
}
int main() {
// Write C code here
x++;
g();
printf("%d",x);
return 0;
}
Output : 22
Here
xin main and the one defined outside g() in global scope are referring to the samex. Also the variablexisexternthrough out the code because of the previous declaration.Try printing the address of
xin the required location.Refer this answer for more info