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

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.

Surya said:   1 decade ago
Nice explanation Sundar.

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

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!

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

Sundar said:   1 decade ago
Hi Haritha,

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

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

Why it is not a declaration?

Post your comments here:

Your comments will be displayed after verification.