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.
Aman said:
8 years ago
a is defined outside the scope of the program. It will not even get executed.
Shubham said:
4 years ago
What is the output of this program? Please anyone explain.
Ajmer thakur said:
9 months ago
The datatype of int is extern so is cancelled to be defined anywhere in the code.
Purnima said:
1 decade ago
Hi friends in my way if we declare extern int a;then we can use the variable a in any line or in may any function through out the programm, .
And if we declare int a;then it is local declaration here we can use a inside of the function only, if that function is closed then we can not use a in in another function.
Is it correct?
And if we declare int a;then it is local declaration here we can use a inside of the function only, if that function is closed then we can not use a in in another function.
Is it correct?
Snehal kadam said:
2 decades ago
In above option is D option correct??
in place of C
in place of C
Snehal kadam said:
2 decades ago
In main, "extern int a" is declaration is ok.
but it is defined in outside;
so ,is the option c is correct???
but it is defined in outside;
so ,is the option c is correct???
Vasudevan said:
2 decades ago
int a=20;(it is a outside of initialization)
how it consider for this program
how it consider for this program
Nandhi said:
1 decade ago
The variables are defined outside the main block, when that variable is declared as with the keyword 'extern'.
Murali krishna said:
1 decade ago
What is the use of "extern" ?
Ravi Karthick said:
1 decade ago
Extern means external declaration that is declared for outside the function,so that a that is declared as extern and defined in outside the main ar a=20
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers