C Programming - Declarations and Initializations - Discussion

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

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

Discussion:
38 comments Page 2 of 4.

Venki said:   2 decades ago
extern here refers to type of storage class in c . If you have 2 files say A and B and you want to access the global variable declared in A to be appearing in B then u culd do so by adding extern keyword . Refer to google if not satisfied .

Naveen Dahiya said:   1 decade ago
I am not agree with Wikiok.

We also can not declare a user defined data type like any structure or union because the memory is also allocated to these (structures or unions) in the same way as it is assigned to any int or float variable.

Sumanta Kundu said:   9 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.

Rishav Jain said:   9 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.

Siji said:   1 decade ago
Whtr int i; is declaration or definition.
Dn external int i; is declaration or definition
Int i=10; is declaration or definition
External int i=10; is declaration or definition

Vasavi said:   1 decade 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.

Abul Asad said:   9 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);

Hirak said:   8 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);

Atul said:   1 decade ago
Sagarborse tells us about prototype not for extern.

Extern is use to get access power to use the data member which is store in other file.

Fajlurrahman said:   1 decade ago
@Pranali.

If the INDIRA is string then char[7]since INDIRA is string so we have to store extra memory location for null character.


Post your comments here:

Your comments will be displayed after verification.