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 5 of 5.

Vishu said:   9 years ago
@Prathyusha.

You are right, answer A is corret.

Aman said:   8 years ago
a is defined outside the scope of the program. It will not even get executed.

Shital said:   7 years ago
If int a=20; is definition, then what about if we say int a=20; is initialisation?
(1)

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

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

Ajmer thakur said:   9 months ago
The datatype of int is extern so is cancelled to be defined anywhere in the code.


Post your comments here:

Your comments will be displayed after verification.