logo CodeStepByStep logo

parameter_mystery12

Language/Type: PHP parameter mystery parameters return
Author: Mehran Sahami (added by Melissa Hovik on 2018/01/05)

The following console program uses parameters and returns to produce four lines of output. What are they?

function add_one() {
    $a = 101;
    $b = 100 + $a + 1;
    print("add_one: a = $a, b = $b\n");
}

function add_two($a, $b) {
    $a += 2;
    $b += 2;
    print("add_two: a = $a, b = $b\n");
    return $b;
}

function add_three_and_return_result($a, $b) {
    $a += 3;
    $b += 3;
    print("add_three_and_return_result: a = $a, b = $b\n");
    return $a;
}

$a = 100;
$b = 100 + $a;
add_one();
$b = add_two($a, $b);
$a = add_three_and_return_result($a, $b);
print("run: a = $a, b = $b\n");
line 1
line 2
line 3
line 4

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.