开发者

segmentation fault for the simplest program?

开发者 https://www.devze.com 2022-12-29 14:29 出处:网络
I am just starting开发者_JAVA百科 out, but this piece of code is giving me a \'segmentation fault\' and I can\'t find out what\'s wrong with it:

I am just starting开发者_JAVA百科 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;

}


scanf("%d", number) is being given the int itself, but actually needs a pointer to the int. Try scanf("%d", &number)


scanf("%d", number);

would be

scanf("%d", &number);

Note the ampersand.


use "&" to store a value after scanning.

scanf("%d", &number);
0

精彩评论

暂无评论...
验证码 换一张
取 消