C Programming - Functions - Discussion

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

[A]. Add prototype: float f(aa, bb)
[B]. Add prototype: float f(int, float)
[C]. Add prototype: float f(float, int)
[D]. Add prototype: float f(bb, aa)

Answer: Option B

Explanation:

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


Nirmal said: (Mar 31, 2012)  
I did not understand. Where to add this prototype. And why it is not option A.

Meghana said: (Aug 30, 2012)  
I did not understand this program. Please explain it.

Karthik said: (Jan 4, 2014)  
@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);
}

Abc said: (Dec 16, 2016)  
You are right @Karthik.

Harish Mahajan said: (Oct 16, 2018)  
I didn't understand please explain it.

Lucky said: (Feb 16, 2020)  
Prototype declaration first next function call and function definition.

Dhaval said: (Jul 26, 2020)  
'a' is of int type and and f is returning floating value, can any one tell me how it is correct?

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.