设为首页 加入收藏

TOP

[编程] C语言的结构体(一)
2018-10-21 20:08:30 】 浏览:175
Tags:编程 语言 结构

结构体

  struct 结构体名{} 变量名;

结构体变量:

        struct person{

                char *name;

                int age;

                float score;

        } student;

成员的获取和赋值

        //Members of the acquisition and assignment

        student.name="taoshihan";

        student.age=30;

        student.score=100;

        printf("name=%s \n",student.name);

C语言结构体数组

        struct stu{

                char *name;

                int age;

                float score;

        } classes[5];

遍历结构体数组

        struct people{

                char *name;

                int age;

                float score;

        } d[]={

                {"taoshihan",20,100},

                {"lisi",30,90}

        };

        int len=sizeof(d)/sizeof(d[0]);

        printf("d length=%d \n",len);

        for(int i=0;i<len;i++){

                printf("loop...%s,%d,%.1f \n",d[i].name,d[i].age,d[i].score);

        }

C语言结构体和指针

  struct 结构体名 *变量名;

        struct person1{

                char *name;

                int age;

                float score;

        }

首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇数据结构 链表_单链表的实现与分析 下一篇STM32系列之学习方法(一)

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目