読者です 読者をやめる 読者になる 読者になる

構造体

C

Advanced Programming in the UNIX Environment: Paperback Edition (Addison-Wesley Professional Computing Series)

Advanced Programming in the UNIX Environment: Paperback Edition (Addison-Wesley Professional Computing Series)


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);
    }
}