Vi) main(){ extern int i; i=20;printf("%d",i);}

Linker Error : Undefined symbol '_i'
Explanation:
extern storage class in the following declaration,
extern int i;
specifies to the compiler that the memory for i is allocated in some other program and that address will be given to the current program at the time of linking. But linker finds that no other variable of name i is available in any other program with memory space allocated for it. Hence a linker error has occurred .

Questions by Beena   answers by Beena

Showing Answers 1 - 6 of 6 Answers

Extern is a key word in C that indicates the scope of a variable or function.
This key word can be used with a variable when it is used across different files of a typical project.

The variable is defined once in a file and in other files where the same variable is used , it is declared as extern variable.

Note : Variable declaration can be multiple but definition is done only once.
Also the extern variables are global to the file where they are defined/declared.

Now if we come to above programm , the comiller will not catch the error but the linker does bcoz for the linker variable "i" is an unresolved variable.It is during the linking stage where definition for this variable "i" is searched for but it not found.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions