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 5 of 5.

Sowma VN said:   1 decade ago
Yes we have to declare extern keyword without that we can't access for both f2 and f3 we have to declare.

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

Knight said:   1 decade ago
The variable declared by using keyword extern point to a memory location which is already defined. If that variable is not defined somewhere else it will leads to a compiler error "undefined reference to a memory location"

VIJAY said:   1 decade ago
We must use extern because we access the value from the external file F1, So we use extern.

Sunil Kumar(S.K) said:   1 decade ago
If we want to use a variable which is defined in another file than it is must that we declare that variable is as extern. If we do not do this than compiler error occur (undefined variable).

Renu said:   1 decade ago
Let us take that 'a' is the variable defined in the file f1 and used in f2 and f3 file for that we have to use the extern declaration because it's is defined in f1 file but if in file f2 & f3 their variable 'a' is defined then it will give priority to local variable and then their is no need for extern declaration.


Post your comments here:

Your comments will be displayed after verification.