10 struct Point double x y int mainvoid
Sign up to view full document!
SIGN UP
10 構造体型の変数. . . struct Point { double x, y; }; int main(void) { struct Point p 1, p 2; . . . メモリ上のレイアウ ト(順番や隙間の大 きさ)は環境による struct Point p 1 double x double y struct Point p 2 double x 「struct + タグ名」で 一つの型名を構成する n 型名として "struct Tag. Name" を使う double y
14 構造体のアクセス n 構造体のメンバは. 演算子を使う. . . typedef struct { double x, y; } Point; struct Point p 1 double x 1. 0 double y 2. 0 メンバ変数を読む int main(void) メンバ変数に代入する { Point p 1 = { 1. 0, 2. 0 }; printf("p 1=(%f, %f)n", p 1. x, p 1. y); p 1. x = -p 1. y; printf("p 1=(%f, %f)n", p 1. x, p 1. y); . . . 出力 p 1=(1. 000000, 2. 000000) p 1=(-2. 000000, 2. 000000)
- Slides: 25