Output and explanation in the link you provided are wrong!
- extern declaration specifies that the variable j is defined somewhere else.
- The compiler passes the external variable to be resolved by the linker.
- So compiler doesn't find any error.
- During linking the linker searches for the definition of j.
- Since it is not found the linker flags an error
#include<stdio.h>
int i=5;
int main()
{
extern int j;
printf("\ni=%d \nj=%d",i,j);
return 0;
}
int j=10; // define j outside main() block.! So linker successfuly finds definition and prints value!