Home » C Programming » Variables » Question
  1. Which of the following is the correct output for the program given below ?
    #include <studio.h>
    int main()
    {
    extern int fun (float);
    int k;
    k = fun (5.74);
    printf ("%d\n", k);
    return 0;
    }
    int fun (kk)
    float kk;
    {
    return ((int) kk);
    }
    1. 3
    2. 5.74
    3. 0
    4. Error
Correct Option: D

The error occurs because we have mixed the ANSI prototype with Kernighan & Ritchie style of function definition.

When we use ANSI prototype for a function and pass a float to the function it is promoted to a double.

When the function accepts this double into a float a type mismatch occurs hence the error. The remedy for this error could be to define the function as:
int fun ( float kk)
{
// code here
}



Your comments will be displayed only after manual approval.