1 / 8

第 6 章 ポインタ

練習問題解説. 第 6 章 ポインタ. P.23 練習問題 ( 問 1) (1). int 型変数 a,b のアドレスを引数として送ると、 a,b の値が入れ替わる関数を作れ. 関数の戻り値の型は?. a と b が入れ替わるという副作用があるだけなので、戻り値なし! ( void ). 関数 の引数は?. a と b のアドレスが必要!! 2 つの ポインタ変数だね!. 骨組みを書いてみよう!!. P.23 練習問題 ( 問 1) (2). 戻り値 はなし. 引数は二つのポインタ変数. void swap( int * a, int * b){ }.

Télécharger la présentation

第 6 章 ポインタ

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 練習問題解説 第6章 ポインタ 第6章 ポインタ(練習問題解説)

  2. P.23 練習問題(問1) (1) int型変数a,bのアドレスを引数として送ると、 a,bの値が入れ替わる関数を作れ 関数の戻り値の型は? aとbが入れ替わるという副作用があるだけなので、戻り値なし!(void) 関数の引数は? aとbのアドレスが必要!! 2つのポインタ変数だね! 骨組みを書いてみよう!! 第6章 ポインタ(練習問題解説)

  3. P.23 練習問題(問1) (2) 戻り値はなし 引数は二つのポインタ変数 void swap(int* a, int* b){ } 何らかの処理 2つの変数を入れ替えるには? もうひとつ変数を作る必要があった 例えば変数a,bを入れ替えるには temp = a; a = b; b = temp; a = b; b = a; 第6章 ポインタ(練習問題解説)

  4. P.23 練習問題(問1) (3) ポインタ変数になっても入れ替えは何も変わらない! 実際に書いてみよう!! void swap(int* a, int* b){ int temp; temp = *a; *a = *b *b = temp; } これで正常に動くよ!! 第6章 ポインタ(練習問題解説)

  5. P.23 練習問題(問2) (1) 点(x,y)をx軸方向にa,y軸方向にb平行移動した 点(x2,y2)を取得する関数を作れ 関数の戻り値の型は? X2とy2を返したい。でも2つ値を返すことはできない! ポインタで値を返そう! だから戻り値はなし(void) 第6章 ポインタ(練習問題解説)

  6. P.23 練習問題(問2) (2) 関数の引数は? 点の座標x,yと 移動したい量 a, b 値を返すためのアドレスx2,y2 が必要だね 骨組みを書いてみよう!! 第6章 ポインタ(練習問題解説)

  7. P.23 練習問題(問2) (3) void multiply(double x, double y, double a, double b, double* x2, double* y2){ } 何らかの処理 実際 x2,y2には何を代入すればいい? 計算しよう!! x2 = x + a y2 = y + b これをx2,y2に代入しよう! 第6章 ポインタ(練習問題解説)

  8. P.23 練習問題(問2) (4) void multiply(double x, double y, double a, double b, double* x2, double* y2){ *x2 = x + a; *y2 = y + b; } これで正常に動くよ!! 第6章 ポインタ(練習問題解説)

More Related