您的位置:首页 > 编程语言 > C语言/C++

黑马程序员——C语言基础——结构体相关练习

2015-06-02 21:28 344 查看
------Java培训、Android培训、iOS培训、.Net培训、期待与您交流! -------

今天整理了C语言基础学习过程中对结构体的一些知识,下面是代码片段:

#include <stdio.h>
#include <string.h>
int main(int argc, const char * argv[]) {
//定义一个结构体
struct student {
int num;            //学号
char name[10];      //姓名
int age;            //年龄
char sex[2];        //性别
float score;        //评分
}studD, studE, studF;   //在声明结构体的同时声明了三个student类型的变量
//定义student类型的结构体变量
struct student studA;   //学生A
struct student studB;   //学生B
struct student studC;   //学生C
studA.num = 1;
strcpy(studA.name, "wangxinyu");
studA.age = 21;
strcpy(studA.sex, "men");
studA.score = 89.57;
printf("该学生序号:%d\n姓名:%s\n年龄:%d\n性别:%s\n评分:%.2f\n",
studA.num, studA.name, studA.age, studA.sex, studA.score);
return 0;
}


学习了C语言的结构体后,感觉和Java的VO比较相似,理解起来轻松了很多。

但是C语言是面向过程的语言,所以其中没有类似对象的概念,故称为结构体。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: