logo CodeStepByStep logo

ReferenceMystery1

Language/Type: C# parameters reference semantics

The following program produces 4 lines of output. Write each line of output below as it would appear on the console.

public class ReferenceMystery1
{
    public static void Main()
    {
        int y = 1;
        int x = 3;
        int[] a = new int[4];

        Mystery(a, y, x);
        Console.WriteLine(x + " " + y + " " + a);

        x = y - 1;
        Mystery(a, y, x);
        Console.WriteLine(x + " " + y + " " + a);
    }

    public static void Mystery(int[] a, int x, int y)
    {
        if (x < y)
        {
            x++;
            a[x] = 17;
        }
        else
        {
            a[y] = 17;
        }
        Console.WriteLine(x + " " + y + " " + a);
    }
}
line 1
line 2
line 3
line 4

You must log in before you can solve this problem.

Log In

Need help?

If you do not understand how to solve an exercise or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect tests, etc.), please

Is there a problem? Contact a site administrator.

©, all rights reserved.