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 5 of 6.
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.
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
Bhyresh said:
9 years ago
What is the difference between int main and extern int main?
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.
Dulal said:
9 years ago
What is the global function?
Sruthi said:
9 years ago
Is the variable declared as extern similar to the variable declared under main?
Harvansh singh said:
9 years ago
What is the actual meaning of extern keyword? Explain clearly.
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" )
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)
Jhansi said:
8 years ago
What is extern? I can't get it.
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.
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.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers