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.

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.

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

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

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

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)

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.

Harish said:   8 years ago
Extern is a keyword to storage class external.

Whose memory allocation will be done in a data area.
SCOPE of the variable with extern declaration is global. (It's reduce code security levels )

Thanks for your example @Keerthi.

Jhansi said:   8 years ago
What is extern? I can't get it.

Keerthi said:   8 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)

Harvansh singh said:   9 years ago
What is the actual meaning of extern keyword? Explain clearly.


Post your comments here:

Your comments will be displayed after verification.