logo CodeStepByStep logo

parameterMystery2X

The following code produces 5 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 s1 variable is stored at address 0x1100
  • main's s2 variable is stored at address 0x2200
  • main's s3 variable is stored at address 0x3300
  • main's s4 variable is stored at address 0x4400
  • main's s5 variable is stored at address 0x5500
  • any memory dynamically allocated on the heap will be at address 0x777700
string* parameterMystery2X(string& s1, string s2) {
    s1 += "1";
    s2 += "2";
    cout << s2 << " -- " << s1 << endl;
    s1 += "!!!";
    return &s1;
}

int main() {
    string s1 = "hi";
    string s2 = "bye";
    string s3 = "yo";
    string* s4 = new string(s3);
    string* s5 = nullptr;

    parameterMystery2X(s1, s3);
    s5 = parameterMystery2X(*s4, s2);
    parameterMystery2X(s2, *s5);

    cout << s1 << " " << s2 << " " << s3 << endl;
    cout << s4 << " " << *s4 << " " << s5 << " " << *s5 << endl;

    return 0;
}
line 1
line 2
line 3
line 4
line 5

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.