【c】结构体(1)

好久没上计蒜客和看书了……

写了个程序,验证计蒜客说的内容

#include <stdio.h>
typedef struct student {
        int age;
        float height;
                       } student;

struct stuent
        {
        int age;
        float height;
        };

struct student Gavin_Belson={56,165.4};//第一种声明方式


int main() {
    struct student Gregory={51,175.4}; //第二种声明方式
    student Amy, Sheldon= {22, 193.2};
    Amy.age = 21; Amy.height = 172.2;//第三种声明方式
    printf("Amy is:%d %f\n", Amy.age, Amy.height);
    printf("Sheldon is:%d %f\n", Sheldon.age, Sheldon.height);
    printf("Gavin_Belson is:%d %f\n", Gavin_Belson.age, Gavin_Belson.height);
    printf("Gregory is:%d %f\n", Gregory.age, Gregory.height);
    return 0;
}

结构体可以在main外声明和定义,也可以在外部使用typedef定义,也可以在外部声明在内部定义

typedef最后的student可以跟在花括号后面也可以空一格,编译器都能识别出来

posted @ 2016-01-03 17:25  1193972689  阅读(154)  评论(0)    收藏  举报