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

C/C++ 之 结构体(1)定义和赋值

2017-09-24 16:18 309 查看

结构体的定义和赋值

# include<stdio.h>

//结构体定义
struct Student
{
int age;
char name;
float score;
};

void main(void)
{
struct Student st = {14,'H',44.4};	//初始化和赋值

struct Student st2; //初始化
st2.age=15;			//赋值
st2.name='J';
st2.score=34.3;

printf("%d %c %f\n", st.age, st.name , st.score);
printf("%d %c %f\n", st2.age, st2.name , st2.score);

}


c中的结构体和java中的类有点相似。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: