Explore BrainMass
Share

Explore BrainMass

    Output for values

    This content was COPIED from BrainMass.com - View the original, and get the already-completed solution here!

    4. Consider the following program in Pascal with static scope:
    program main (input, output);
    var i, j, k, m: integer;
    procedure Q (var i: integer; m: integer);
    begin
    i := j + 1;
    m := k + 1;
    writeln (i, j, k, m);
    end
    procedure P(var i: integer; j: integer);
    var k: integer;
    procedure S(i: integer)
    begin
    i := k + 3;
    m := i + 3;
    writeln(i, j, k, m);
    end
    begin
    k := 8;
    i := i + k;
    j := j + k;
    Q(i, j);
    writeln(i, j, k, m);
    S(m);
    writeln(i, j, k, m);
    end
    begin
    i := 5;
    j := 2;
    k := 7;
    m := 9;
    writeln(i, j, k, m);
    P(i, k);
    writeln(i, j, k, m);
    Q(j, m);
    writeln(i, j, k, m);
    end
    Please fill in the following table with the values of i, j, k, and m for each writeln
    statement. Assume use call by value
    Place of writeln statement i: J: k: m:
    1. In Main, before calling P
    2. In Q
    3. In P after Q
    4. In S
    5. IN P after S
    6. In Main after P
    7. In Q
    8. In Main

    © BrainMass Inc. brainmass.com June 1, 2020, 4:31 pm ad1c9bdddf
    https://brainmass.com/computer-science/algorithms/output-for-values-100222

    Solution Preview

    Solution:

    i j k m
    1. 5 2 7 9 as given in problem

    2. 3 2 7 8 i,m are local to Q passed from P ...

    $2.19

    ADVERTISEMENT