C Programming - Declarations and Initializations - Discussion
Discussion Forum : Declarations and Initializations - General Questions (Q.No. 9)
9.
Identify which of the following are declarations
1 : | extern int x; |
2 : | float square ( float x ) { ... } |
3 : | double pow(double, double); |
Answer: Option
Explanation:
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.
double pow(double, double); - is a function prototype declaration.
Therefore, 1 and 3 are declarations. 2 is definition.
Discussion:
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.
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!
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.
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?
Why it is not a declaration?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers