edited by
3,612 views

2 Answers

Best answer
7 votes
7 votes

Difference between extern int and int =>

  • Extern int A only declares that there is some identifier A which will be used in the program
  • int A declares that there is some identifier A which will be used in the program as well as allocates memory for it to store some value.

Here, you are only declaring the identifier A and memory allocation is not there .

When memory is not allocated, then it is a compiler error to initialize the variable .

selected by
1 votes
1 votes
It will not compile.

Hence, the answer should be c.

Reason: When a variable is declared extern, then it will be only treated as declared which means no definition is given for that variable which again means that no memory allocation is done. So, this is what extern is used for.

Let me know if you want to understand it in more depth as there is one exception as well.

Related questions

2 votes
2 votes
1 answer
1
rahul sharma 5 asked Nov 23, 2017
1,055 views
#include <stdio.h int main() { int a=10; extern int a; return 0;} Why this gives compilation error? Extern is just a declaration.So why it is giving error on c...
0 votes
0 votes
1 answer
3
Na462 asked Nov 19, 2018
1,494 views
1 votes
1 votes
0 answers
4