C Programming - Declarations and Initializations - Discussion

Discussion Forum : Declarations and Initializations - General Questions (Q.No. 10)
In the following program where is the variable a getting defined and where it is getting declared?
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

- During declaration we tell the datatype of the Variable.

- During definition the value is initialized.

44 comments Page 1 of 5.

Om tripathi said:   1 decade ago
int a=20; is outside the main

Snehal kadam said:   1 decade ago
In main, "extern int a" is declaration is ok.
but it is defined in outside;
so ,is the option c is correct???

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

Vasudevan said:   1 decade ago
int a=20;(it is a outside of initialization)
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

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!.....

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?

Post your comments here:

Your comments will be displayed after verification.