干杯们。我在编写此代码时遇到了麻烦。它的所有功能都很好,但是当我猜对时打印出数字时,它会打印出-3529583这样的数字,我无法理解。洒了些光?
#include <stdio.h>
#include <ctype.h>
#include <time.h>
int main()
{
int y, iRandomNum1; // Declare the three variables
y = 0;
iRandomNum1 = 0;
srand(time(NULL)); // Randomize function
iRandomNum1 = rand() % 10; // Randomize and collect 1 to 10 Value
while (iRandomNum1 != y) {
printf("Guess a number from 1 to 10\n");
scanf("%d", &y);
}
printf("\nCorrect Guess! Congrats! The answer is %d.\n", &y);
return 0;
}
答案 0 :(得分:1)
您将在&y
中显示变量printf
的地址,而不是变量本身,只需删除&
符号就可以了
https://stackoverflow.com/users/2173917/sourav-ghosh在我的评论中得到了答案