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;
extern int a is declaration, int a = 20 is the definition
int a = 20 is declaration, extern int a is the definition
int a = 20 is definition, a is not defined
a is declared, a is not defined
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.

Vasudevan said:   2 decades ago
int a=20;(it is a outside of initialization)
how it consider for this program

Aman said:   1 decade ago
When we have need to declare the extern variables? and what are its Benefits?

Aniket said:   2 years ago
It shows an error msg because extern are declared inside the function.
(1)

Ajit Darnal said:   1 decade ago
Definition int a=20 ; is outside the main, how it is possible ?

Shwetha said:   1 decade ago
since int a=20; is in outside of the main() it is definition.

Teja said:   1 decade ago
What is this extern function? How and where it can be used?

Shubham said:   4 years ago
What is the output of this program? Please anyone explain.

Susee said:   1 decade ago
May I know explanation for "return 0"? What it will do?

Deepak said:   9 years ago
Here, we should declare a=20 above the main function.

Snehal kadam said:   2 decades ago
In above option is D option correct??
in place of C


Post your comments here:

Your comments will be displayed after verification.