What will be the output of the following program?#include<stdio.h>int main() { int fun(int); int i = fun(10); printf("%d\n", --i); return 0; } int fun(int i) { return (i++);}Select one:810119
Question
What will be the output of the following program?#include<stdio.h>int main() { int fun(int); int i = fun(10); printf("%d\n", --i); return 0; } int fun(int i) { return (i++);}Select one:810119
🧐 Not the exact question you are looking for?Go ask a question
Solution
The output of the program will be 10. Here's the step-by-step explanation:
- The function
fun(int)is declared in themain()function. - The variable
iis initialized with the value returned byfun(10). - In the
fun(int)function, the passed value 10 is returned and then incremented. However, because the increment (i++) is postfixed, the increment happens after the value is returned. So,fun(10)returns 10. - Back in the
main()function,iis now 10. Theprintfstatement decrementsiby 1 before printing, so--iis 9. - However, the decrement operation is not saved in the variable
i, so wheniis printed, it's still 10. - Therefore, the output of the program is 10.
Similar Questions
What is the output of the following C Program?
What will be the output of the following code?
what will be the output of the c program?
What will be the output of the following C++ code?
What will be the output of the following program?Note: This question helps in clearing the AMCAT exam
1/4
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.