• 検索結果がありません。

郢晄亢縺ケ晢スウ郢ァソ邵コィ闕ウ?隹コ。陷?陋サ?br/>

N/A
N/A
Protected

Academic year: 2021

シェア "郢晄亢縺ケ晢スウ郢ァソ邵コィ闕ウ?隹コ。陷?陋サ?br/>"

Copied!
3
0
0

読み込み中.... (全文を見る)

全文

(1)

1

ポインタと一次元配列

学習のポイント ポインタを用いて一次元配列を参照する方法を学びます。  配列のデータはメモリ上に順序正しく格納されていますので、ポインタを用いて配列の 要素を参照することができます。  このように、Cではポインタと配列は密接な関係にあります。 例えば int a[10]; という配列があったとき、この配列をポインタで参照するには、ポインタ変数paを用 いて、 int *pa; pa = a; とします。  配列名 a は配列の先頭アドレスを持つポインタ定数と考えることができますので、 pa=a;により、配列の先頭アドレスがpaに代入されます。したがって、*paとすること によりa[0]の内容を参照でき、ポインタpaを進めることによりa[1]、a[2]、・・・の内容 を次々に参照することができます。「C言語」(河西朝雄著 ナツメ社)87頁

(2)

1.1

例題

16

一次元配列のデータをポインタを用いて取り出す。配列データの終わりは-999とする。 /* 例題16 C言語87頁 一次元配列のデータをポインタを用いて取り出す。 配列データの終わりは-999とする。 reidai16.c */ #include <stdio.h> int main() {

static int a[] = {10, 35, 25, 67, 88, 29, -999}; int *pa; pa = a; while(*pa != -999){ printf("%d\n", *pa); pa++; } return 0; } 2

(3)

1.2

練習問題

16

例題16と同じことを long型データについて行なうプログラムを作りなさい。なおそ の際ポインタの値も表示しなさい。 /* 練習問題16 C言語87頁 例題16と同じことをlong型データについて行なうプログラムを作りなさい。 なおその際ポインタの値も表示しなさい。 rensyu6.c */ #include <stdio.h> int main() {

static long a[] = {10L, 35L, 25L, 67L, 88L, 29L, -999L}; long *pa;

pa = a;

while(*pa != -999L){

printf("%04x %ld\n", pa, *pa); pa++;

}

return 0; }

参照

関連したドキュメント

Here, instead of considering an instance I and trying to directly develop a feasible solution for the P, G ∗ |prec; c ij dπ k , π l 1; p i 1|C max problem, we consider a

There is a bijection between left cosets of S n in the affine group and certain types of partitions (see Bjorner and Brenti (1996) and Eriksson and Eriksson (1998)).. In B-B,

We establish sharp Br´ezis-Gallou¨et-Wainger type inequalities in Besov and Triebel-Lizorkin spaces as well as fractional Sobolev spaces on a bounded domain Ω ⊂ R n.. We treat

(The Elliott-Halberstam conjecture does allow one to take B = 2 in (1.39), and therefore leads to small improve- ments in Huxley’s results, which for r ≥ 2 are weaker than the result

[r]

“Breuil-M´ezard conjecture and modularity lifting for potentially semistable deformations after

lines. Notice that Theorem 4 can be reformulated so as to give the mean harmonic stability of the configuration rather than that of the separate foliations. To this end it is

S., Oxford Advanced Learner's Dictionary of Current English, Oxford University Press, Oxford