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

Venkat said:   8 years ago
@ALL.

extern is keyword .

When we use this word before the variable then that will store in the stack.
extern int a;
main()
{
-----
-----
}

In above program, I declared but not assigned so "a" value may present in other programs then you will get that value by using extern without this we can not get it.

The same way when function declares with extern we can get from other programs. But our compiler assumes that if you do not mention extern (in function concept only) it treats as extern.
(2)

Venkatesh said:   9 months ago
@All.

Here is my explanation.
1) extern and global are the same thing but when we use the keyword "extern" is important.
2) extern use only for function and variable and use when you assign an extern then don't assign value it raises an error.
3) The directly say that use on extern is you access the variable or function inside as well as outside file.
(1)

Neha said:   7 years ago
I am not understanding this, please explain it for me.
(1)

Keerthi said:   9 years ago
Extern is a data storage type or storage class.
extern is a global variable.
Scope of the global variable is global.

Eg:-
file1.c

include "file2.c"
main()
{
extern int a;
printf(",,...d",a);
}


file2.c

int a;

extern points to the int a of file2.c(another file) .
Because file1.c refers to file2.c (#include "file2.c" )
(1)

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.

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

Eshwar said:   1 decade ago
Hi,

How is extern function different from normal function?

If a function is declared as extern, then that function can be overrided?

Sirisha said:   1 decade ago
What is global function and why extern keyword used to declare a function?

Vijay sawant said:   1 decade ago
extern int a;

extern keyword tell the compiler, identifier a of type integer define anywhere through the program. This statement is just declaration.

Vijay said:   1 decade ago
@Ragveni.

Global variable means that the variable which are defined outside all the blocks of functions, anywhere in file (not only before main).

main()
{
pf("hello");
}
int a;

a is global variable.


Post your comments here:

Your comments will be displayed after verification.