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 3 of 6.

Coder said:   1 decade ago
All functions are defined as extern in default.
If we declare a function as, int foo() actually it is taken as
extern int foo.

Chand890 said:   1 decade ago
What is extern?

Sm das said:   1 decade ago
It is a keyword which functioning same as global and local variables.

Vijay said:   1 decade ago
Why we use extern function in C?

Subhasish said:   1 decade ago
Could anybody please tell me what is the scope for extern, I mean; say we have two files in two different directories I want to use one variable/function of file1 in file2 but those 2 are in diff. Directories. So can I access the elements of file1 in file2 using extern?

Pradeep said:   1 decade ago
Does storage classes can be used with data types and keywords.

Preethe said:   1 decade ago
What is meant by global variables? please explain.

Mumukshu said:   1 decade ago
The answer is incorrect. In C language, by default all function declarations are extern as C does not support local functions. Extern func(); and func(); are the same.

Ragaveni said:   1 decade ago
Variables which are declared before main function i.e. not in any function are called global variables.

Radheshyam said:   1 decade ago
"Extern" is keyword in C ,suppose you write 2 diff. function in diff. file and main function in third file,

And you want one variable use globally eg. int a;

At that time we use extern keyword eg. extern int a;

This procedure same for function.


Post your comments here:

Your comments will be displayed after verification.