C Programming - Functions - Discussion
Discussion Forum : Functions - Find Output of Program (Q.No. 20)
20.
What will be the output of the program?
#include<stdio.h>
int fun(int);
int main()
{
float k=3;
fun(k=fun(fun(k)));
printf("%f\n", k);
return 0;
}
int fun(int i)
{
i++;
return i;
}
Discussion:
21 comments Page 1 of 3.
Onkar said:
1 decade ago
The answer should be garbage value. When 3 is passed to fun (int i) by value, a variable I gets created at location say 100. At this 100th location the value of I gets incremented to 4. When the return statement is called its returning a value at the 100th location which 'i' doesn't occupy anymore as it was a local variable.
Shivani said:
5 years ago
Here is fun( k=fun(fun)).
So, k = 2 times increment ie 5.
It will be 6 if k=fun(fun(fun))).
So, k = 2 times increment ie 5.
It will be 6 if k=fun(fun(fun))).
Kukku said:
5 years ago
It is returning an integer value, but it prints integer value using floats format specifier (%f) , so it prints that value as float.
Aashis said:
7 years ago
How is it possible?
If a float value and accepting it in an integer data type. It should show error.
If a float value and accepting it in an integer data type. It should show error.
Rutul said:
8 years ago
In C, no function overloading concept so it shows error.
TUSHAR said:
9 years ago
@skp.
Yes, it is possible to convert float to int by type casting.
Yes, it is possible to convert float to int by type casting.
Manjubharathi said:
9 years ago
Thanks for explanation. Now I get it.
Skp said:
10 years ago
Is it possible to convert float to int?
Kavi said:
1 decade ago
main()
{
int k=35,z;
k=fun(k=fun(k=fun(k)));
printf("k=%d",k);
}
fun(int k)
{
k++;
return(k);
}
What will be the output of the program? When it evaluates first time the fun will be k=fun (k=fun (k=36)); it will assign the value k=36 but after what will be the output?
{
int k=35,z;
k=fun(k=fun(k=fun(k)));
printf("k=%d",k);
}
fun(int k)
{
k++;
return(k);
}
What will be the output of the program? When it evaluates first time the fun will be k=fun (k=fun (k=36)); it will assign the value k=36 but after what will be the output?
Jagan mohan reddy said:
1 decade ago
In main function fun (fun (n). So 2 times, so value incremented by 2 times, value is 5.0000.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers