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

void change(int x)
{
    x = 100;
}

int main()
{
    int a = 20;
    change(a);
    cout << a;
}
                        

Options

  • A. 20
  • B. 100
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

A. 20

Detailed Explanation

Answer: (A) 20

In pass-by-value, the function receives a copy of the argument.

Therefore, the parameter x is a separate copy of a.

Changing x to 100 does not change the original variable a.

Consequently, cout << a prints 20.