What is the output of the following C++ code segment in Dev C++ under Windows…

2022

What is the output of the following C++ code segment in Dev C++ under Windows 10 operating system?

int sum(int a, int b=10, int c=20)
{
return a+b+c;
}
int main(){
cout<<sum(20,30);
}

  1. A.

    50

  2. B.

    60

  3. C.

    70

  4. D.

    80

Attempted by 118 students.

Show answer & explanation

Correct answer: C

The function sum uses default parameters b=10 and c=20. When called with sum(20,30), a becomes 20 and b becomes 30. Parameter c retains its default value of 20. The calculation is 20+30+20=70.

Explore the full course: Uppsc Polytechnic Lecturer 2025 Cs