首页 > 其他 > 详细

【c】结构体(1)

时间:2016-01-03 18:06:03      阅读:185      评论:0      收藏:0      [点我收藏+]

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

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

#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可以跟在花括号后面也可以空一格,编译器都能识别出来

【c】结构体(1)

原文:http://www.cnblogs.com/xiayezhige/p/5096776.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!