I think I don't understand very well the concept of how compiler and linker work. This could be the reason why I am stuck in this code
Output generated by program
Why does line 11 print 101, I was expecting X = 43 ?
C:
#include<stdio.h>
int X;
void foo(){
int X = 42;
printf("X = %d \n", X);
{
extern int X;
++X;
printf("X = %d \n", X); // Why does this line print 101, I was expecting X = 43
}
printf("X = %d \n", X);
}
int main(){
X = 100;
printf("X = %d \n", X);
foo();
printf("X = %d \n", X);
return 0;
}
C:
X = 100
X = 42
X = 101
X = 42
X = 101
Last edited: