int a = 0, b = 0, ture = 0, i = 0,j=0;
int answer = 0,score=0;
int Score[10] = { 0 };
for (i = 0; i<10; i++)
{
a = rand() % 10;
b = rand() % 10;
ture = a + b;//正确答案
printf("第%d题:%d+%d=\n",i, a, b);
printf("请输入正确答案:");
scanf_s("%d", &answer);
if (answer == ture)
{
score = 10 - j;
printf("答对了,这一题得分是%d", score);
printf("\n");
}
else
{
while (answer != ture && 0 < j < 3)
{
j++;
printf("答错了\t请再输入一次\t你还有%d次机会", 3 - j);
scanf_s("%d", &answer);
}
if (answer == ture)
{
score = 10 - j;
printf("答对了,你的得分是%d", score);
}
else
{
printf("答错了,你的得分是0");
score = 0;
}
}
Score[i] = score;
}
int sum = 0;
sum = sum + Score[i];
printf("你的总成绩是%d", sum);
return 0;
}
数组名同时也是改数组首元素的地址。
dates +2 ==&dates[2] //相同的地址
*(dates +2) == dates[2] //相同的值
对地址进行加操作,相当于是地址增加两个元素的字节地址。*对地址进行取值操作。
i在for循环结束时为10,Score[10]导致溢出