Knowee
Questions
Features
Study Tools

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:

  1. The function fun(int) is declared in the main() function.
  2. The variable i is initialized with the value returned by fun(10).
  3. 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.
  4. Back in the main() function, i is now 10. The printf statement decrements i by 1 before printing, so --i is 9.
  5. However, the decrement operation is not saved in the variable i, so when i is printed, it's still 10.
  6. Therefore, the output of the program is 10.

This problem has been solved

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.