C Programming - Declarations and Initializations - Discussion
Discussion Forum : Declarations and Initializations - General Questions (Q.No. 10)
10.
In the following program where is the variable a getting defined and where it is getting declared?
#include<stdio.h>
int main()
{
extern int a;
printf("%d\n", a);
return 0;
}
int a=20;
Answer: Option
Explanation:
- During declaration we tell the datatype of the Variable.
- During definition the value is initialized.
Discussion:
46 comments Page 4 of 5.
Sindhu said:
1 decade ago
int a=20 is outside the main() so it is not considered as a declaration for a in given program
Prathyusha said:
1 decade ago
Hi friends!
here in the program please go through the question again.he was just asking where "a" is declared and where it is defined.
whether "a" is normal integer or external integer not matters.
so,declaration is : extern int a;
and definition is :int a=20;
that's it!....
correct me if i am wrong plz!.....
here in the program please go through the question again.he was just asking where "a" is declared and where it is defined.
whether "a" is normal integer or external integer not matters.
so,declaration is : extern int a;
and definition is :int a=20;
that's it!....
correct me if i am wrong plz!.....
Kavita.C.Karjagar said:
1 decade ago
1.What is the difference between int a and extern int a?
2.when we use extern int a and int a?
2.when we use extern int a and int a?
Satyadev said:
1 decade ago
The definition of 'a' outside the function main is not valid, so it is not considered.
M.DHILIP BABU said:
1 decade ago
Why was declared int a=20 outside? suppose int a=20 declared inside of the function what is the o/p of this program?
Om tripathi said:
2 decades ago
int a=20; is outside the main
Aman said:
1 decade ago
When we have need to declare the extern variables? and what are its Benefits?
Bhavana said:
1 decade ago
I agree with prathyusha.
Mayank said:
1 decade ago
extern int a; indicates that the variable a is defined elsewhere, usually in a separate source code module.
printf("%d\n", a); it prints the value of local variable int a = 20. Because, whenever there is a conflict between local variable and global variable, local variable gets the highest priority. So it prints 20.
printf("%d\n", a); it prints the value of local variable int a = 20. Because, whenever there is a conflict between local variable and global variable, local variable gets the highest priority. So it prints 20.
Rathika.b said:
1 decade ago
Please give an real example for "extern" keyword; Then only we know that how it works.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers