C Programming - Declarations and Initializations - Discussion

Discussion Forum : Declarations and Initializations - Find Output of Program (Q.No. 8)
8.
What is the output of the program
#include<stdio.h>
int main()
{
    extern int fun(float);
    int a;
    a = fun(3.14);
    printf("%d\n", a);
    return 0;
}
int fun(int aa)
{
	return (int)++aa;
}
3
3.14
4
Compile Error
Answer: Option
Explanation:
2 Errors
1. Type mismatch in redeclaration of fun
2. Type mismatch in parameter aa
Discussion:
35 comments Page 3 of 4.

Abinaya said:   10 years ago
I too don't understand the 2nd error. Please explain me.

Pooja said:   10 years ago
Error: Previous declaration of 'fun' was here.

Can anybody explain me the meaning of the above error?

Anjaneyareddy said:   10 years ago
@Pooja.

Function declaration means like Declaring a variable.

Like when ever you are using Function, that must be matched to the Function Definition.

Syntax for Function Declaration is:

Type functionName (type [argname] [,type,.]);

Example:

Declare a function prototype for the add function, taking two integer.

//Arguments and returning their sum.

int add (int lhs, int rhs);

Sourav sachdeva said:   10 years ago
The first error seems obvious with mismatch of float and input in declaration and definition but can anyone cover the 2nd one in mismatch of parameters (is it referring to float and int), I think both are referring to same thing.

Rohan said:   9 years ago
extern int fun(float).

In this statement "extern" also there. So that's means the memory of this function allocated in some other program. So this is one of the error.
(1)

Panu said:   9 years ago
How two functions are mismatch?

Ssindham said:   9 years ago
Great discussion.

Thanks @Suman, Amlan Karmakar, @Neha, @Rekha @Nishanth.

Dnyanu said:   9 years ago
Thank you all for the explanation.
(1)

Suraj said:   8 years ago
After passing the argument to the function need its type of float than in the function it increment the value of a then you get the answer 4.
(1)

Udhaya said:   8 years ago
#include<stdio.h>
int main()
{
extern int fun(float);
float a;
a = fun(3.14);
printf("%d\n", a);
return 0;
}
int fun(float a)
{
return (int)++a;
}

This give output '0'.
(4)


Post your comments here:

Your comments will be displayed after verification.