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));
}
Discussion:
49 comments Page 5 of 5.
Gopichand said:
1 decade ago
Please any one can explain me clearly.
Nayana said:
1 decade ago
@Vasuroshan, thank you for your explaination.
Ravitheja said:
1 decade ago
if (a=b), i.e if both values are equal, then it returns 0;
if (a<b), i.e if a is less than b, then it returns -1;
if (a>b), i.e if a is greater than b, then it returns 1;
if (a<b), i.e if a is less than b, then it returns -1;
if (a>b), i.e if a is greater than b, then it returns 1;
Nagaraj said:
1 decade ago
Thanks vishwas.
Diana said:
1 decade ago
Excellent answer!!Vishwas
Ashok said:
1 decade ago
Thank you vishwas.
Siri said:
1 decade ago
Simple:
The return statement in proc function is replaced like this:
return( fun(a,b));
Which means calling the function fun(a,b).
Since it returns a==b and integer value of true is 1, the output is 1.
The return statement in proc function is replaced like this:
return( fun(a,b));
Which means calling the function fun(a,b).
Since it returns a==b and integer value of true is 1, the output is 1.
Abhishek said:
1 decade ago
@Ashish.
#include<stdio.h>
int fun(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)
{
return (a=9);
}
int proc(pf p, int a, int b)
{
return ((*p)(a, b));
}
Guys please help me out ...this program is returning 9 as output how it is possible? bcoz pf is defined as taking 2 variables of type int and returning an int..but in this program i mentioned only a function fun with single argument.so as i think program must show error but it is providing a output 9.can someone tell me how it is possible?????????
In c there is no strict checking in compilation time it means that u can pass 1 value during the function calling time or at receiving time function parameter once time a program has been compiled by compiled so it would run....
int fun(int a)
{
return (a=9); //a is assigned to 9 not compared.
}
proc(fun, 6,6)// it would be changed as proc(address of fun, 6,6)
Address of fun containing the value of a=9
#include<stdio.h>
int fun(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)
{
return (a=9);
}
int proc(pf p, int a, int b)
{
return ((*p)(a, b));
}
Guys please help me out ...this program is returning 9 as output how it is possible? bcoz pf is defined as taking 2 variables of type int and returning an int..but in this program i mentioned only a function fun with single argument.so as i think program must show error but it is providing a output 9.can someone tell me how it is possible?????????
In c there is no strict checking in compilation time it means that u can pass 1 value during the function calling time or at receiving time function parameter once time a program has been compiled by compiled so it would run....
int fun(int a)
{
return (a=9); //a is assigned to 9 not compared.
}
proc(fun, 6,6)// it would be changed as proc(address of fun, 6,6)
Address of fun containing the value of a=9
Preethi said:
2 decades ago
What does proc mean and give me its syntax?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers