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

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

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?

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.

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.

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

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?

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.

Mumukshu said:   1 decade ago
The answer is incorrect. In C language, by default all function declarations are extern as C does not support local functions. Extern func(); and func(); are the same.

Preethe said:   1 decade ago
What is meant by global variables? please explain.


Post your comments here:

Your comments will be displayed after verification.