C Programming - Declarations and Initializations - Discussion

Discussion Forum : Declarations and Initializations - General Questions (Q.No. 4)
4.
Is there any difference between following declarations?
1 : extern int fun();
2 : int fun();
Both are identical
No difference, except extern int fun(); is probably in another file
int fun(); is overrided with extern int fun();
None of these
Answer: Option
Explanation:

extern int fun(); declaration in C is to indicate the existence of a global function and it is defined externally to the current module or in another file.

int fun(); declaration in C is to indicate the existence of a function inside the current module or in the same file.

Discussion:
56 comments Page 5 of 6.

Manas said:   1 decade ago
The extern keyword means "declare without defining". In other words, it is a way to explicitly declare a variable, or to force a declaration without a definition. It is also possible to explicitly define a variable, i.e. to force a definition. It is done by assigning an initialization value to a variable. If neither the extern keyword nor an initialization value are present, the statement can be either a declaration or a definition. It is up to the compiler to analyse the modules of the program and decide.

Sanket V Garg said:   1 decade ago
If we declare any functions external as well as an internal function in same code then if latter that function is called from anywhere in file the which function will be loaded? how is the issue of function resolved in these scenario? can anyone please explain these to me?

Prakash said:   1 decade ago
Then 'extern' keyword not understand, please explain.

Hasi said:   1 decade ago
Global function is nothing but the variables which are used for overall program. Where as local variables are used in specific function or a specific part of the program.

Ganesh said:   1 decade ago
Hi sir you said extern is globally declared where as int fun you said localy declared so how you can so it is not different.

Wikiok said:   1 decade ago
@Nancy: http://wiki.answers.com/Q/What_is_the_use_of_extern_in_C

"Declaring a variable as extern will result in your program not reserving any memory for the variable in the scope that it was declared."

Nancy said:   1 decade ago
While using extern keyword, memory is allocated to variable or not?

Pankaj said:   1 decade ago
The extern int fun(); is nothing but it can be declared globlly means out side the function.

But int fun(); can be declared in local means in the function only.

Sirajmuneer said:   1 decade ago
extern refers to suppose inside a local variable in main() we can access outside this variable its called extern and the same as fun() can be accessed
syntax:
main()
{
extern int s; //external declaration
}
fun1()
{
extern int s; //external declaration
}

int y; //definition

Smsirajmuneer said:   1 decade ago
'extern' is similar to the gloabal declaration we can access any where in the program module, similar to accessing the functions in .dll files from various .exe files.


Post your comments here:

Your comments will be displayed after verification.