关于#c语言# 结构体


#include 

#define N 2
struct Student
{
    char name[4];
    float score;
};
main()
{
    struct Student stu[N];
    int i = 0;
    for (; i < N; i++)
    {
        printf("input scores of student%d:\n", i + 1);
        printf("name:");
        scanf("%s", stu[i].name);
        printf("score:");
        scanf("%f", &stu[i].score);
    }
}

请问最后一行 scanf要用"&" 符号是因为它时数组的第二个元素吗?
第一个不用是因为数组名即首元素地址

跟数组的第几个元素无关,对于基本类型的数据输入,scanf函数参数要求变量取地址。因为score是浮点型,所以要加&取地址。上面name是字符串,所以不需要取地址,字符串是char数组,数组名本身就是地址,你加上&后,效果是一样的

scanf("yyyy",xxxxx); 这第二个参数xxxxx必须是地址。 你的score不是地址,当然要 & 去取地址。
你的name是数组名 ,也代表地址,所以不用。