Both the codes are not correct in C.
arjun@Armi:~$ gcc -O1 a.c
a.c:2:12: warning: ‘a’ initialized and declared ‘extern’
2 | extern int a = 20;
| ^
Just that in the second case since “initialization” of an extern variable is done outside of any function, memory is allocated statically (before any function gets executed) and so the code works ignoring “extern”, albeit with a warning. If “-Werror” parameter is given as in most production codes, this will turn to an error. In other words “initialization” should not be done while using “extern”.