Knowee
Questions
Features
Study Tools

What is the output of following program?# include <stdio.h>void fun(int x){    x = 30;}int main(){  int y = 20;  fun(y);  printf("%d", y);  return 0;}a.30b.20c.Compile errord.Run error

Question

What is the output of following program?# include <stdio.h>void fun(int x){    x = 30;}int main(){  int y = 20;  fun(y);  printf("%d", y);  return 0;}a.30b.20c.Compile errord.Run error

🧐 Not the exact question you are looking for?Go ask a question

Solution

The output of the given program is "20".

Here is the step-by-step explanation:

  1. The program defines a function called "fun" that takes an integer parameter "x". Inside the function, the value of "x" is assigned as 30, but this assignment does not affect the value of the variable passed from the main function.

  2. In the main function, an integer variable "y" is declared and initialized with the value 20.

  3. The function "fun" is called with the argument "y". This means that the value of "y" is passed to the "fun" function.

  4. Inside the "fun" function, the parameter "x" is assigned the value 30. However, this assignment does not affect the value of "y" in the main function because the parameter "x" is a separate variable.

  5. After the function call, the printf statement is executed, which prints the value of "y" (which is still 20) to the console.

  6. Finally, the main function returns 0, indicating successful execution of the program.

Therefore, the output of the program is "20".

This problem has been solved

Similar Questions

What is the output of the following C Program?

What is the output for the following code?

What is the output of the following Java program?

What will be the output of the following C++ code?

What is the output of the following code in Python?

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.