• edited by
5,220 views

2 Answers

Best answer
7 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 1 vote
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.
Position:
Show:

Related questions

6 6 votes
2 2 answers
218
218 views
GO Classes asked Jun 10
218 views
What is the output of the following code?#include <stdio.h int main() { extern int i; printf("%d", i); return 0; } int i = 100;Garbage value $\texttt{0}$ $\texttt{100}$ C...
3 3 votes
1 1 answer
1.5k
1.5k views
rahul sharma 5 asked Nov 23, 2017
1,458 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...
3 3 votes
1 1 answer
3.3k
3.3k views
Shubhanshu asked Jun 11, 2017
3,298 views
extern int var;int main(void){ var = 10; // why it is not considered as definition in prog return 0;}Why this is creating error saying (var is not defined).But as per ...
0 0 votes
1 answers 1 answer
2.3k
2.3k views
Na462 asked Nov 19, 2018
2,271 views