+ 2
The extern keyword indicates that this variable was defined elsewhere, for example, when creating large projects, all global variables can be stored in a separate file, and subroutines are scattered across other files. That is, extern essentially copies the variable. This increases the compilation speed. In your case, extern is not required, "main" and this how sees the given variable.
12th Jul 2021, 12:27 PM
Solo
Solo - avatar
+ 2
Mahmoud Osman Because you declared two different variables, one global, the other local, and it will throw an error because the local variable is not used. Write "return printf("%d%d", a, get_a());" and there will be an output: 65
13th Jul 2021, 9:07 PM
Solo
Solo - avatar
+ 1
Verstappen Because you are re-initialising a by 6 so your output will be 6
12th Jul 2021, 11:44 AM
A͢J
A͢J - avatar
+ 1
Verstappen, I'm glad I was able to help you, you can mark my answer as the best ☺️
12th Jul 2021, 3:31 PM
Solo
Solo - avatar
+ 1
😉
12th Jul 2021, 3:56 PM
Solo
Solo - avatar
+ 1
Why not to : int a = 5; int get_a (void) { return a; } int main(void) { int a = 6; return printf ("%d", get_a()) ; }
13th Jul 2021, 7:50 PM
Mahmoud Osman
Mahmoud Osman - avatar