结构体变量的初始化和赋值

下面是一段结构体变量初始化和赋值的小程序:

#include 
struct Student
{
    int age;
    float score;
    char sex;
};
int main(void)
{
    //定义并赋值称之为初始化
    struct Student st1 = {80, 66.0F, 'F'};
    //定义声明结构体变量st2, st2的类型是struct Student
    struct Student st2;
    //给st2赋值。
    st2.age = 10;
    st2.score = 88;
    st2.sex = 'M';
    printf("%d %f %c\n", st1.age, st1.score, st1.sex);
    printf("%d %f %c\n", st2.age, st2.score, st2.sex);
    return 0;
}

你可能感兴趣的:(c)