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

Ranjith said:   8 years ago
What the extern function to do?

But how could you say that there is no difference between the two? Please tell me.

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)

Suraj said:   7 years ago
Thanks for explaining the answer.

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

Bhargavi said:   7 years ago
Please tell the difference between extern and static, automatic.

Venkatesh said:   8 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.


Post your comments here:

Your comments will be displayed after verification.