logo CodeStepByStep logo

parameterMystery12

The following code produces 4 lines of output. What is the output? Write each line of output as it would appear on the console.

For the purposes of this problem, assume that the variables in main are stored at the following memory addresses:

  • main's a variable is stored at address 0xaa00
  • main's b variable is stored at address 0xbb00
  • main's c variable is stored at address 0xcc00
  • main's d variable is stored at address 0xdd00
  • main's e variable is stored at address 0xee00
  • any memory allocated on the heap (using new) will be at address 0x777700
int mystery(int* a, int b, int& c) {
    c++;
    b--;
    *a = (c + b);
    cout << *a << " " << b << " " << c << endl;
    return b;
}

int main() {
    int a = 1;
    int b = 30;
    int c = 500;
    int* d = new int;
    *d = a;
    int* e = &b;

    mystery(d, c, b);
    b = mystery(&c, a, *e);

    cout << a << " " << b << " " << c << " " << d << " " << e << endl;
    cout << &a << " " << &b << " " << &c << " " << *d << " " << *e << endl;
    return 0;
}

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.