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

Sajla said:   1 decade ago
We can able to call the file by using extern keyword only because the file is external file.

Arsh said:   1 decade ago
because only extern variables can be used in more than one file and to inform the compiler that these are declare some other file it needs to specify the keyword extern,

Saravana said:   1 decade ago
If the sub functions f1 and f2 share the function f1 datatypes, no need to specify again the datatypes, otherwise we have to mention extern.

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.

Makadiya dhara said:   1 decade ago
Without extern keyword we can not access the variable with in outside file to another file.

Thiruneelakandar.s said:   1 decade ago
Global variable declaration is we can access to any of the function or files.

Want to know more details down to follow here.

First up all we want to know about data types or storage class.

There are 4 classes.

1. Local variable.
2. Static variable.
3. Global variable.
4. Register variable.

Local variable only to use a function. We cannot access other function and life is a function only.

Static variable is one or more function to use, the static variable is update automatically.

Global variable is declaration the variable is out side the function, so we can use the variable in any of the function.

Register variable declaration only internal the CPU memory.

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.

Pavan kumar said:   1 decade ago
We want to declare the variable extern in file f1 or f2?

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.

RohitN said:   1 decade ago
In C every variable or function which is defined in a file other than the one in which it is getting used, is declared as 'extern'.


Post your comments here:

Your comments will be displayed after verification.