CS 70

Before You Start

Consider the following code snippet:

int x = 5;
int y = x;
y = 10;
cout << x << " " << y;

Draw a memory diagram of this snippet (really draw it, please!) and then give the printed output:

Key point: assignment is copying data from one place to another place.

  • RHS Cow speaking

    The line int y = x; initializes a separate variable that just happens to have the same value as x. Nothing you do to x after this point will affect yand vice-versa.

(When logged in, completion status appears here.)