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 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)

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)

Pooja said:   7 years ago
Yes, but we have to declare that variable globally in f1 file also.

C.kumar said:   7 years ago
Can anyone please explain with example?
(1)

Shivashish Bagora said:   7 years ago
Yes, definitely if you declare a variable of extern storage class. That means it has a global variable and it can use throughout the code in another file also.

Sneha said:   8 years ago
Variables are declared in f1 file. To use variables of f1 in f2&f3 extern keyword must be used.

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.

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?
(2)

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


Post your comments here:

Your comments will be displayed after verification.