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);
}
Add prototype: float f(aa, bb)
Add prototype: float f(int, float)
Add prototype: float f(float, int)
Add prototype: float f(bb, aa)
Answer: Option
Explanation:

The correct form of function f prototype is float f(int, float);

Discussion:
7 comments Page 1 of 1.

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);
}

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?

Nirmal said:   1 decade ago
I did not understand. Where to add this prototype. And why it is not option A.

Lucky said:   6 years ago
Prototype declaration first next function call and function definition.

Meghana said:   1 decade ago
I did not understand this program. Please explain it.

Harish Mahajan said:   7 years ago
I didn't understand please explain it.

Abc said:   9 years ago
You are right @Karthik.

Post your comments here:

Your comments will be displayed after verification.