C Programming - Declarations and Initializations - Discussion

Discussion Forum : Declarations and Initializations - General Questions (Q.No. 9)
Identify which of the following are declarations
1 : extern int x;
2 : float square ( float x ) { ... }
3 : double pow(double, double);
1 and 3
Answer: Option
extern int x; - is an external variable declaration.

double pow(double, double); - is a function prototype declaration.

Therefore, 1 and 3 are declarations. 2 is definition.
37 comments Page 1 of 4.

Haritha said:   1 decade ago
float square ( float x ) { ... }

Why it is not a declaration?

Sundar said:   1 decade ago
Hi Haritha,

It is the actual definition for the function 'square', which may or may not be declared previously.

Swathi bhat said:   1 decade ago
What does double pow mean?

Sundar said:   1 decade ago
@Swathi Bhat

double pow(double, double);

It is a function prototype declaration. It should be defined somewhere in the program module. It denotes the following

1. Function name is 'pow'
2. It should called with 2 arguments of type 'double'
3. It will return a double value as result.

If you want to call the function then use the following method:

double Result;
Result = pow(5, 4);

Hope you can understand this. Have a nice day!

Aishu said:   1 decade ago
Can you tel me what is the difference between declaration and definition and state some examples?

Surya said:   1 decade ago
Nice explanation Sundar.

Jaz said:   1 decade ago
int a;
is the declaration, it simply assigns the datatype for the variable.

int a=10; is the definition, it assigns the value for the variable, the value given should match d datatype.

Vivek patel said:   1 decade ago
Thanks to all for a good answers.

Ramarao mundru said:   1 decade ago

file f1.c
extern int a;//declaration because it doesn't allocate memory for a variable,it has allocated memory somewhere else in the program
file f2.c
int a;// it is definition because here it is getting memory

a=3;//it is assigment

Naveen goud said:   1 decade ago

A declaration is just writing a type of variable or function.

a definition is simply assigning a values to that particular variable or function.

Post your comments here:

Your comments will be displayed after verification.