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 3 of 5.
Riddhi said:
1 decade ago
Yes we have to declare extern here for multi use of variables because if we don't use extern then compiler gives error.
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.
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)
Tuks said:
1 decade ago
Declaration of global variables should not be within any fun.
It should be out of all fun i.e. before main.
It should be out of all fun i.e. before main.
Susi said:
1 decade ago
Without extern keyword we can not access from the variable with in outside file to inside (or) another file.
Priya said:
9 years ago
Without extern keyword we can not access from the variable with in outside file to inside (or) another file.
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.
Renu said:
1 decade ago
Yes, we need to declare a extern keyword variable in other files of program where we want to use it.
Divyapriya said:
1 decade ago
Yes, we need to declare a extern keyword variable in other files of program where we want to use it.
Sneha said:
8 years ago
Variables are declared in f1 file. To use variables of f1 in f2&f3 extern keyword must be used.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers