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?
Discussion:
46 comments Page 1 of 5.
Sai Naveen said:
7 years ago
Here we can declare the variable name f1 globally, so it can be used anywhere in the program.
(3)
Thejas_Mysore said:
9 years ago
How the variable extern a at file_2 or file_3 is link with the variable a at file_1?
f1()
{
int a;
}
f2()
{
extern int a;
}
Where these two get linked?
f1()
{
int a;
}
f2()
{
extern int a;
}
Where these two get linked?
(2)
Aashu sharma said:
7 years ago
Without extern keyword, we can not access from the variable within outside file to the inside (or) another file.
(1)
Sudhir said:
7 years ago
There are three files f1 f2 and f3 which are part of the single program not functions. How they are separated and how they are linked to each other? Explain me.
(1)
C.kumar said:
7 years ago
Can anyone please explain with example?
(1)
Supriya said:
1 decade ago
Yes we need to specify the extern because we are taking the data from the other file.
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.
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.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers