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 3 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
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?
Rathika.b said:
1 decade ago
Please give an real example for "extern" keyword; Then only we know that how it works.
Satyadev said:
1 decade ago
The definition of 'a' outside the function main is not valid, so it is not considered.
Sunil Kumar said:
1 decade ago
I think option D is correct because we never put semicolon after function definition.
Ayush said:
1 decade ago
In this question the extern keyword is used inside the function which is prohibited.
Anjan said:
1 decade ago
If int a=20; then is it int a is declaration and a=20 defination?
Please clear me.
Please clear me.
Shital said:
7 years ago
If int a=20; is definition, then what about if we say int a=20; is initialisation?
(1)
Ajmer thakur said:
9 months ago
The datatype of int is extern so is cancelled to be defined anywhere in the code.
Aman said:
8 years ago
a is defined outside the scope of the program. It will not even get executed.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers