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

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.

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?

Arvind kumar said:   1 decade ago
It gives the address of memory location so we can use the specific value.

Arzoo said:   1 decade ago
Please explain function using extern keyword with proper example.

Adithya said:   1 decade ago
Oh horrible explanation. By declaring a variable as an extern, you just tell the compiler that a variable has been declared. Without an extern, something like this:

int x;

The compiler declares as well as defines (i.e, allocates memory to the variable x). No wonder why extern is used in declaring a variable that's gonna be used across various files.

Raj said:   1 decade ago
Can anyone tell me how can we access one C program to another one with external variable.

Revathi said:   10 years ago
What is the different between normal function and extern function?


Post your comments here:

Your comments will be displayed after verification.