C Programming - Declarations and Initializations - Discussion

Discussion Forum : Declarations and Initializations - General Questions (Q.No. 8)
Is the following statement a declaration or definition?
extern int i;
Answer: Option

Declaring is the way a programmer tells the compiler to expect a particular type, be it a variable, class/struct/union type, a function type (prototype) or a particular object instance. (ie. extern int i)

Declaration never reserves any space for the variable or instance in the program's memory; it simply a "hint" to the compiler that a use of the variable or instance is expected in the program. This hinting is technically called "forward reference".

38 comments Page 1 of 4.

Mrinmoy said:   5 years ago
This is a statement I think which is telling the compiler that x is an external variable.

The declaration is "int x;" which is declared anywhere in the program & without "int x;" line "extern int x;" will do nothing with x because this line itself is not a declaration.

Hema said:   5 years ago
Give me clear information of extern.

Rohith said:   6 years ago
Please tell me exact explanation of declaration and definition.

Hirak said:   6 years ago
What is the difference between the following two declarations of a function myfunction?

a) void myfunction (int a[ ]);
b) void myfunction (int *a);

Rishav Jain said:   7 years ago
@Abul Asad.

Both are same, address of a is passed as an argument.
In both cases, function will receive the address of a.
In the case of array a[], address of a[0] will be automatically initialised.

Abul Asad said:   7 years ago
What is the difference between the following two declarations of a function myfunction?

a) void myfunction (int a[ ]);
b) void myfunction (int *a);

Sumanta Kundu said:   7 years ago
int i=0 is a declaration.

But if we write
extern int i;
Then, it becomes a definition because this extern variable reserves space for 'i' and initializes 'i' to zero.

The answer given is wrong. So,the correct answer will be option B.

Rahul Chauhan said:   8 years ago
Declaration of a variable/function simply declares that the variable/function exists somewhere in the program but the memory is not allocated for them.

Definition: We define a variable/function, apart from the role of the declaration, it also allocates memory for that variable/function.

Initialization: When we assigned the value of a variable.


// This is the only declaration. y is not allocated memory by this statement
extern int y;

// This is both declaration and definition, memory to x is allocated by this statement.
int x;

// This is initialization.
x = 94;

Hiral said:   9 years ago
What is difference between declaration, definition and initialization? Please help.

Vasavi said:   10 years ago
int i;----is declaration.
int i=0;--is definition.
extern int i;--declaration.

Why because this statement declares that int i is already defined somewhere.

Post your comments here:

Your comments will be displayed after verification.