1. コード メモリの内容
出力
5. int x = 1;
6. int *p;
7. p = &x;
8. *p = 2;
9. cout << x << endl;
10.
11. int y;
12. y = *p;
13. cout << y << endl;
初期状態
x
p
y
2. コード メモリの内容
出力
5. int x = 1;
6. int *p;
7. p = &x;
8. *p = 2;
9. cout << x << endl;
10.
11. int y;
12. y = *p;
13. cout << y << endl;
xの定義(x = 1)
x
p
y
1
3. コード メモリの内容
出力
5. int x = 1;
6. int *p;
7. p = &x;
8. *p = 2;
9. cout << x << endl;
10.
11. int y;
12. y = *p;
13. cout << y << endl;
pの定義
x
p
y
1
4. コード メモリの内容
出力
5. int x = 1;
6. int *p;
7. p = &x;
8. *p = 2;
9. cout << x << endl;
10.
11. int y;
12. y = *p;
13. cout << y << endl;
xのアドレスをpに代入
x
p
y
(xのアドレス)
1
5. コード メモリの内容
出力
5. int x = 1;
6. int *p;
7. p = &x;
8. *p = 2;
9. cout << x << endl;
10.
11. int y;
12. y = *p;
13. cout << y << endl;
pの指す先に2を書き込む
x
p
y
(xのアドレス)
2
6. コード メモリの内容
出力
5. int x = 1;
6. int *p;
7. p = &x;
8. *p = 2;
9. cout << x << endl;
10.
11. int y;
12. y = *p;
13. cout << y << endl;
xの値を出力 2
x
p
y
(xのアドレス)
2
7. コード メモリの内容
出力
5. int x = 1;
6. int *p;
7. p = &x;
8. *p = 2;
9. cout << x << endl;
10.
11. int y;
12. y = *p;
13. cout << y << endl;
yを定義 2
x
p
y
(xのアドレス)
2
8. コード メモリの内容
出力
5. int x = 1;
6. int *p;
7. p = &x;
8. *p = 2;
9. cout << x << endl;
10.
11. int y;
12. y = *p;
13. cout << y << endl;
yに「pの指す先の値」を代入 2
x
p
y
(xのアドレス)
2
2
9. コード メモリの内容
出力
5. int x = 1;
6. int *p;
7. p = &x;
8. *p = 2;
9. cout << x << endl;
10.
11. int y;
12. y = *p;
13. cout << y << endl;
xの値を出力 2
2
x
p
y
(xのアドレス)
2
2
10. コード メモリの内容
出力
5. int x = 1;
6. int *p;
7. p = &x;
8. *p = 2;
9. cout << x << endl;
10.
11. int y;
12. y = *p;
13. cout << y << endl;
2
2
x
p
y
(xのアドレス)
2
2