C Programming - Declarations and Initializations - Discussion

Discussion Forum : Declarations and Initializations - Yes / No Questions (Q.No. 2)
2.
Suppose a program is divided into three files f1, f2 and f3, and a variable is defined in the file f1 but used in files f2 and f3. In such a case would we need the extern declaration for the variables in the files f2 and f3?
Yes
No
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
46 comments Page 2 of 5.

Priya said:   9 years ago
Without extern keyword we can not access from the variable with in outside file to inside (or) another file.

Pavan said:   9 years ago
No variables defined in f1 so it should be declared.

Anson Cardoz said:   9 years ago
No variables defined in f1. So it should be declared as extern.

Amandeep said:   10 years ago
As variable are used in file f2 and f3. So extern should be used for references.

Hemanth Kumar M said:   1 decade ago
If 'a' is declared in file f1, To access 'a' in other files we have to declare 'a' as extern in other files. Otherwise it will show it as error.

Undefined 'a'. When a is declared as extern it will indicate that it is defined in other file and control starts to lookup for 'a' in other files.

Riddhi said:   1 decade ago
Yes we have to declare extern here for multi use of variables because if we don't use extern then compiler gives error.

Apurva said:   1 decade ago
Because extern is act as the global declaration.

Manasa said:   1 decade ago
We will use the extern keyword for f1 and when we use it for f1 no need of defining the keyword extern before f2 and f3 values can access the f1.

Madhuri said:   1 decade ago
Since, we want to use the variable in another file. We use extern keyword. It connects the links with files f1, f2, f3.

Shubham sharnma said:   1 decade ago
If we declare extern keyword then translation unit of all program will connect all f1, f2, f3 files if we not do this then translation unit will limited to one source file and the linkage between all files will not connected internally.


Post your comments here:

Your comments will be displayed after verification.