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

Praveen IIIT said:   1 decade ago
Yes, If you want access Programs in other files, you must declare a extern keyword.

Mohan said:   1 decade ago
Yes with you extern declaration , we cannot use the variable in f2 , f3 which was declared in the f1.

f1()
{
variable v1;
}

Extern f2()
{
used v1;
}

Extern f3()
{
used v1;
}

Aarthi said:   1 decade ago
Yes, because a variable declared in one file is local to it. Therefore in order to access that variable in another file it must be given the correct access authority. Therefore Extern keyword is used.

Phantom said:   1 decade ago
Yes Extern keyword is to be used while we define the variable in file f1 so as to make this same variable accessible in the file f2 and f3. Since not using extern will make the variable local inside the file f1.

Supriya said:   1 decade ago
Yes we need to specify the extern because we are taking the data from the other file.

Gaurav saini said:   1 decade ago
Yes Extern keyword is to be used while we define the variable in file f1 so as to make this same variable accessible in the file f2 and f3. Since not using extern will make the variable local inside the file f1. And that time for it act like global variable.

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.

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.

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.


Post your comments here:

Your comments will be displayed after verification.