#include <stdio.h>
struct stu
{
int number;
double *score;
};
int main()
{
struct stu student[4];
scanf("%lf,",&student[0].score[0]);
printf("%f",student[0].score[0]);
return 0;
}
输出根本没反应😭😭😭
#include <stdio.h>
struct stu
{
int number;
double *score;
};
int main()
{
struct stu student[4];
scanf("%lf,",&student[0].score[0]);
printf("%f",student[0].score[0]);
return 0;
}
输出根本没反应😭😭😭
struct stu student[4];这里声明了数组,但是数组元素的score没有初始化,scanf("%lf,",&student[0].score[0]);这里使用的时候程序会崩的。
参考如下:
#include <stdio.h>
struct stu
{
int number;
double *score;
};
int main()
{
struct stu student[4];
double arr[3];
student[0].score = arr; //这里是你想要的指针和数组的转换,但是一般不这么用,会破坏结构体的封装性
scanf("%lf,",&student[0].score[0]);
printf("%f",student[0].score[0]);
return 0;
}