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(); |
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.
Sruthi said:
9 years ago
Is the variable declared as extern similar to the variable declared under main?
Dulal said:
9 years ago
What is the global function?
Bahubali said:
9 years ago
What we declare before the main function it is called global declaration. Then we can use that variable any where in the program. If we declare the variable inside the main function it is called locally declaring the variable. We can use that variable only in specified function not out side the main function.
Bhyresh said:
9 years ago
What is the difference between int main and extern int main?
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
The syntax is:
extern string-literal { declaration-list }
extern string-literal declaration
PRIYANKA CHAVAN said:
10 years ago
In C there are four storage classes.
1) Automatic = Auto, its lifetime is within the fun. By default it is garbage initialization.
2) Static = Life cycle of static is throughout the program, default value is 0.
3) Extern = It is global variable. Outside the function, treated as global variable only.
Ex:
int a;(global variable)
main()
{
a=4; (local variable)
printf(a);
mdify();
printf(a);
}
modify()
{
a=a+1;
printf(a)
}
Hope it is clear.
1) Automatic = Auto, its lifetime is within the fun. By default it is garbage initialization.
2) Static = Life cycle of static is throughout the program, default value is 0.
3) Extern = It is global variable. Outside the function, treated as global variable only.
Ex:
int a;(global variable)
main()
{
a=4; (local variable)
printf(a);
mdify();
printf(a);
}
modify()
{
a=a+1;
printf(a)
}
Hope it is clear.
Revathi said:
10 years ago
What is the different between normal function and extern function?
Raj said:
1 decade ago
Can anyone tell me how can we access one C program to another one with external variable.
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.
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.
Arzoo said:
1 decade ago
Please explain function using extern keyword with proper example.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers