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.

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.

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

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

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)

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)

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)


Post your comments here:

Your comments will be displayed after verification.