结构体的定义和赋值
# 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中的类有点相似。
本文介绍了C语言中结构体的基本定义及使用方法,包括结构体的初始化与赋值过程,并通过示例代码展示了如何操作结构体成员变量。

被折叠的 条评论
为什么被折叠?



