最简单程序的分段错误?
我才刚刚开始,但是这段代码给了我一个“分段错误”,我无法找出它出了什么问题:
#include<stdio.h>
int main (void) {
int number = 0;
int lastDigit = 0;
printf("Enter an integer: ");
scanf("%d", number);
number = number*10;
printf("Number times ten is %d.\n", number);
return 0;
}
I am just starting out, but this piece of code is giving me a 'segmentation fault' and I can't find out what's wrong with it:
#include<stdio.h>
int main (void) {
int number = 0;
int lastDigit = 0;
printf("Enter an integer: ");
scanf("%d", number);
number = number*10;
printf("Number times ten is %d.\n", number);
return 0;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
scanf("%d", number)
被赋予了int
本身,但实际上需要一个int指针代码>.尝试
scanf("%d", &number)
scanf("%d", number)
is being given theint
itself, but actually needs a pointer to theint
. Tryscanf("%d", &number)
请
注意&符号。
would be
Note the ampersand.
使用“&”扫描后存储一个值。
use "&" to store a value after scanning.