C Programming - Functions - Discussion
Discussion Forum : Functions - Point Out Correct Statements (Q.No. 2)
2.
There is a error in the below program. Which statement will you add to remove it?
#include<stdio.h>
int main()
{
int a;
a = f(10, 3.14);
printf("%d\n", a);
return 0;
}
float f(int aa, float bb)
{
return ((float)aa + bb);
}
Answer: Option
Explanation:
The correct form of function f prototype is float f(int, float);
Discussion:
7 comments Page 1 of 1.
Dhaval said:
5 years ago
'a' is of int type and and f is returning floating value, can any one tell me how it is correct?
Lucky said:
6 years ago
Prototype declaration first next function call and function definition.
Harish Mahajan said:
7 years ago
I didn't understand please explain it.
Abc said:
9 years ago
You are right @Karthik.
Karthik said:
1 decade ago
@Nirmal and @Meghana the correct program is:
float f(int, float); //just add the prototype here.
int main()
{
int a;
a = f(10, 3.14);
printf("%d\n", a);
return 0;
}
float f(int aa, float bb)
{
return ((float)aa + bb);
}
float f(int, float); //just add the prototype here.
int main()
{
int a;
a = f(10, 3.14);
printf("%d\n", a);
return 0;
}
float f(int aa, float bb)
{
return ((float)aa + bb);
}
Meghana said:
1 decade ago
I did not understand this program. Please explain it.
Nirmal said:
1 decade ago
I did not understand. Where to add this prototype. And why it is not option A.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers