構造体

- 作者: W. Richard Rago, Stephen A. Stevens
- 出版社/メーカー: Addison-Wesley Professional
- 発売日: 2005/06/17
- メディア: ペーパーバック
- クリック: 4回
- この商品を含むブログ (2件) を見る
Advanced Programming in the UNIX Environmentを輪講するんだけど、まずはCを理解してないと!
以下、「プログラミング言語C」の第6章の自分的なメモ。
#include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { struct point { int x; int y; }; struct point p1 = { 10, 20 }; struct point *pp = &p1; // the same results printf("%d,%d\n", p1.x, p1.y); printf("%d,%d\n", (*pp).x, (*pp).y); printf("%d,%d\n", pp->x, pp->y); // array of struct struct point points[3] = { { 10, 20 }, { 20, 30 }, { 30, 40 }, }; int i; for ( i =0 ; i < 3; i++ ) { printf("x is %d\n", points[i].x); } }