C Programming - Functions - Discussion

Discussion Forum : Functions - Find Output of Program (Q.No. 10)
10.
What will be the output of the program?
#include<stdio.h>
int fun(int, int);
typedef int (*pf) (int, int);
int proc(pf, int, int);

int main()
{
    printf("%d\n", proc(fun, 6, 6));
    return 0;
}
int fun(int a, int b)
{
   return (a==b);
}
int proc(pf p, int a, int b)
{
   return ((*p)(a, b));
}
6
1
0
-1
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
49 comments Page 2 of 5.

Hema said:   8 years ago
@Vishwas.

Thanks for your explanation.

Prashant said:   8 years ago
@Vishwas.

Thank you, your explanation was easy to understand.

Aadarsh said:   8 years ago
First statement of main - printf("%d\n" ,proc(fun,6,6);

Calls the function int proc(pf p, int a, int b). This function returns to int fun(int a, int b).the return statement here a==b is true since a=b=6.Hence it returns 1. So the answer is B- 1.

Saroj said:   8 years ago
Please, anyone explain me clearly.

Mompp said:   9 years ago
Basically function return to the operating system either 0 or 1.

Here (a==b) means return 1 and now,

(1,6,6) all are non-zero values so the output will be 1(a non-zero number)

I hope you all understand.

Ashish Patil said:   9 years ago
Thanks to all of your explanation.

Ashwini Gour said:   9 years ago
Thanks, @Manukundloo.

Azagumozhi said:   9 years ago
Nice answer @Vishwas.

Thenu said:   9 years ago
@Vishwas.

Thanks, Clearly understood.

XYZ said:   1 decade ago
How this happened?


Post your comments here:

Your comments will be displayed after verification.