SlideShare a Scribd company logo
コード メモリの内容
出力
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
コード メモリの内容
出力
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
コード メモリの内容
出力
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
コード メモリの内容
出力
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. 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
コード メモリの内容
出力
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
コード メモリの内容
出力
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
コード メモリの内容
出力
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
コード メモリの内容
出力
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
コード メモリの内容
出力
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

More Related Content

What's hot

C++でHello worldを書いてみた
C++でHello worldを書いてみたC++でHello worldを書いてみた
C++でHello worldを書いてみた
firewood
 
みんな大好き! Hello, World
みんな大好き! Hello, Worldみんな大好き! Hello, World
みんな大好き! Hello, WorldNaohiro Aota
 
C++0x in programming competition
C++0x in programming competitionC++0x in programming competition
C++0x in programming competition
yak1ex
 
新しくプログラミング言語・・・Rubyでやってみた
新しくプログラミング言語・・・Rubyでやってみた新しくプログラミング言語・・・Rubyでやってみた
新しくプログラミング言語・・・RubyでやってみたTomoaki Ueda
 
プロトコル指向 - 夢と現実の狭間 #cswift
プロトコル指向 - 夢と現実の狭間 #cswiftプロトコル指向 - 夢と現実の狭間 #cswift
プロトコル指向 - 夢と現実の狭間 #cswift
Tomohiro Kumagai
 
言語処理系入門4
言語処理系入門4言語処理系入門4
言語処理系入門4
Kenta Hattori
 
String representation in py3k
String representation in py3kString representation in py3k
String representation in py3k
Atsuo Ishimoto
 
Goの文法の実例と解説
Goの文法の実例と解説Goの文法の実例と解説
Goの文法の実例と解説
Ryuji Iwata
 
すごいConstたのしく使おう!
すごいConstたのしく使おう!すごいConstたのしく使おう!
すごいConstたのしく使おう!
Akihiro Nishimura
 
X hago2 shortcoding 20110827
X hago2 shortcoding 20110827X hago2 shortcoding 20110827
X hago2 shortcoding 20110827
uskey512
 
ナウなヤングにバカうけのイカしたタグ付き共用体
ナウなヤングにバカうけのイカしたタグ付き共用体ナウなヤングにバカうけのイカしたタグ付き共用体
ナウなヤングにバカうけのイカしたタグ付き共用体
digitalghost
 
Swift 3 を書くときに知っておきたい API デザインガイドライン #love_swift #akibaswift
Swift 3 を書くときに知っておきたい API デザインガイドライン #love_swift #akibaswiftSwift 3 を書くときに知っておきたい API デザインガイドライン #love_swift #akibaswift
Swift 3 を書くときに知っておきたい API デザインガイドライン #love_swift #akibaswift
Tomohiro Kumagai
 
Emcjp item21
Emcjp item21Emcjp item21
Emcjp item21
MITSUNARI Shigeo
 
Mock and patch
Mock and patchMock and patch
Mock and patch
Toru Furukawa
 
Protocol-Oriented Integers に想うジェネリックプログラミングの未来
Protocol-Oriented Integers に想うジェネリックプログラミングの未来Protocol-Oriented Integers に想うジェネリックプログラミングの未来
Protocol-Oriented Integers に想うジェネリックプログラミングの未来
Tomohiro Kumagai
 
templateとautoの型推論
templateとautoの型推論templateとautoの型推論
templateとautoの型推論
MITSUNARI Shigeo
 
AVAの話 #mentaicojs
AVAの話 #mentaicojsAVAの話 #mentaicojs
AVAの話 #mentaicojs
Hiroyuki Anai
 

What's hot (19)

C++でHello worldを書いてみた
C++でHello worldを書いてみたC++でHello worldを書いてみた
C++でHello worldを書いてみた
 
業務報告会
業務報告会業務報告会
業務報告会
 
初めてのSTL
初めてのSTL初めてのSTL
初めてのSTL
 
みんな大好き! Hello, World
みんな大好き! Hello, Worldみんな大好き! Hello, World
みんな大好き! Hello, World
 
C++0x in programming competition
C++0x in programming competitionC++0x in programming competition
C++0x in programming competition
 
新しくプログラミング言語・・・Rubyでやってみた
新しくプログラミング言語・・・Rubyでやってみた新しくプログラミング言語・・・Rubyでやってみた
新しくプログラミング言語・・・Rubyでやってみた
 
プロトコル指向 - 夢と現実の狭間 #cswift
プロトコル指向 - 夢と現実の狭間 #cswiftプロトコル指向 - 夢と現実の狭間 #cswift
プロトコル指向 - 夢と現実の狭間 #cswift
 
言語処理系入門4
言語処理系入門4言語処理系入門4
言語処理系入門4
 
String representation in py3k
String representation in py3kString representation in py3k
String representation in py3k
 
Goの文法の実例と解説
Goの文法の実例と解説Goの文法の実例と解説
Goの文法の実例と解説
 
すごいConstたのしく使おう!
すごいConstたのしく使おう!すごいConstたのしく使おう!
すごいConstたのしく使おう!
 
X hago2 shortcoding 20110827
X hago2 shortcoding 20110827X hago2 shortcoding 20110827
X hago2 shortcoding 20110827
 
ナウなヤングにバカうけのイカしたタグ付き共用体
ナウなヤングにバカうけのイカしたタグ付き共用体ナウなヤングにバカうけのイカしたタグ付き共用体
ナウなヤングにバカうけのイカしたタグ付き共用体
 
Swift 3 を書くときに知っておきたい API デザインガイドライン #love_swift #akibaswift
Swift 3 を書くときに知っておきたい API デザインガイドライン #love_swift #akibaswiftSwift 3 を書くときに知っておきたい API デザインガイドライン #love_swift #akibaswift
Swift 3 を書くときに知っておきたい API デザインガイドライン #love_swift #akibaswift
 
Emcjp item21
Emcjp item21Emcjp item21
Emcjp item21
 
Mock and patch
Mock and patchMock and patch
Mock and patch
 
Protocol-Oriented Integers に想うジェネリックプログラミングの未来
Protocol-Oriented Integers に想うジェネリックプログラミングの未来Protocol-Oriented Integers に想うジェネリックプログラミングの未来
Protocol-Oriented Integers に想うジェネリックプログラミングの未来
 
templateとautoの型推論
templateとautoの型推論templateとautoの型推論
templateとautoの型推論
 
AVAの話 #mentaicojs
AVAの話 #mentaicojsAVAの話 #mentaicojs
AVAの話 #mentaicojs
 

apg4b 4.05 ポインタ