C Programming - Declarations and Initializations - Discussion
Discussion Forum : Declarations and Initializations - General Questions (Q.No. 8)
8.
Is the following statement a declaration or definition?
extern int i;
extern int i;
Answer: Option
Explanation:
Declaring is the way a programmer tells the compiler to expect a particular type, be it a variable, class/struct/union type, a function type (prototype) or a particular object instance. (ie. extern int i)
Declaration never reserves any space for the variable or instance in the program's memory; it simply a "hint" to the compiler that a use of the variable or instance is expected in the program. This hinting is technically called "forward reference".
Discussion:
38 comments Page 4 of 4.
Appu said:
1 decade ago
int i=1;
This statement is definition or declaration ?
Anybody help me?
This statement is definition or declaration ?
Anybody help me?
Sandeep said:
1 decade ago
When you want all your program variables and functions to use a particular defined value then that could be declared as EXTERN.
More clearly...When many functions or variables need to access a particular variable whose value should be the same for all those which refer it (even if the defined value is changed. All those should access the same new value) then "extern" is used.
More clearly...When many functions or variables need to access a particular variable whose value should be the same for all those which refer it (even if the defined value is changed. All those should access the same new value) then "extern" is used.
Sureshkumar said:
1 decade ago
Where should I use extern? can you tell little deeper.
Atul said:
1 decade ago
Sagarborse tells us about prototype not for extern.
Extern is use to get access power to use the data member which is store in other file.
Extern is use to get access power to use the data member which is store in other file.
Sagarborse said:
1 decade ago
When we are declaring any function after main() function then we declare it before its use which is declaration
and what that method is going to invoke that code is its definition
Example:
void show(); //Declaration
void main(){
show(); //Call to method
}
void show(){ //Definition
printf("Hello!");
}
But what is declaration and definition in context of Variable?
and what that method is going to invoke that code is its definition
Example:
void show(); //Declaration
void main(){
show(); //Call to method
}
void show(){ //Definition
printf("Hello!");
}
But what is declaration and definition in context of Variable?
Rahul said:
1 decade ago
Why we use extern keyword?
Venki said:
1 decade ago
extern here refers to type of storage class in c . If you have 2 files say A and B and you want to access the global variable declared in A to be appearing in B then u culd do so by adding extern keyword . Refer to google if not satisfied .
Antony said:
1 decade ago
What actually here mean by "extern" ?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers