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.

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.

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

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.

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.

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

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

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

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

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

Farman said:   9 years ago
If any variable define in file f1 with extern keyword then it can be used in file f1, f2 because when we define any variable with extern then it will become atomic in the kernel so all atomic varible can be used in different different file.


Post your comments here:

Your comments will be displayed after verification.