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 2 of 5.
Pooja said:
1 decade ago
External variable is declared as:
extern <data_type> <var>;
It is present in another program and we are refering it.
So we have to define it outside the main().....
extern <data_type> <var>;
It is present in another program and we are refering it.
So we have to define it outside the main().....
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
Laxmi said:
9 years ago
extern int a=2; it is a definition. Because variable a is initialized to 2 then memory is created for a. That's why we call it as a definition.
Mounika said:
10 years ago
Absolutely option A is correct answer.
But, declaration is outside of the main function.
So, could you please explain more about that?
But, declaration is outside of the main function.
So, could you please explain more about that?
Pawan Asati said:
1 decade ago
option A is correct because extern is a storage class so a is treated as global variable so it definition can be out of main we write.
Jyoti mishra said:
1 decade ago
What is the program for this output?
*
* *
* * *
* * * *
* * * * *
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???
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?
Nandhi said:
1 decade ago
The variables are defined outside the main block, when that variable is declared as with the keyword 'extern'.
Anusha said:
10 years ago
If we give like this extern int a = 2;
Is it a declaration or definition?
Please can someone explain this?
Is it a declaration or definition?
Please can someone explain this?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers