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

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?

Khusi 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?

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?

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.

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.

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."

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.

Anum said:   9 years ago
Extern is a keyword, which informs the compiler that the function or variable has external linkage.

The syntax is:

extern string-literal { declaration-list }
extern string-literal declaration

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.

Shyojee ram meena said:   1 decade ago
Declaration means that the variable exist in program :-

#include<stdio.h>
main()
{
int a;
printf("%d",&a);
return 0;
}
Why it gives address of memory location?


Post your comments here:

Your comments will be displayed after verification.