c求助,为什么不能用指针
查看原帖
c求助,为什么不能用指针
1161140
wen_wen_wen楼主2023/11/24 20:47
#define _CRT_SECURE_NO_WARNINGS 1
#include"stdio.h"
struct student {
	char *name=NULL;
	int years;
	int score;
}stu[10];


int main() {
	int n, y, z, i;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%s%d%d", stu[i].name, 		  &stu[i].years, &stu[i].score);
		stu[i].years++;
		stu[i].score *= 1.2;
		if (stu[i].score >= 600) stu[i].score = 600;

	}
	for (i = 0; i < n; i++) {
		printf("%s %d %d\n", stu[i].name, stu[i].years, stu[i].score);
	}
	return 0;
}

好像是访问越界的问题

把name改成数组就AC了

但是为什么指针不能用,搞不明白

求大佬解惑

2023/11/24 20:47
加载中...