Got stuck with Segmentation Fault Error

后端 未结 2 1980
攒了一身酷
攒了一身酷 2021-01-27 15:40

I\'m writing a simple program in c and I\'m got stuck with this error

Segmentation Fault (Core dumped)

I know Se

2条回答
  •  醉酒成梦
    2021-01-27 16:31

    Change

    scanf("%d", a);
    

    to

    scanf("%d", &a);
    

    scanf needs a pointer to a variable, not the value of a variable.

    I can suggest you to add -Wall option when you compile. In your case gcc will warn you:

    test.c: In function ‘main’:
    test.c:25:5: warning: format ‘%d’ expects argument of type ‘int *’, but argument 2 has type ‘int’ [-Wformat=]
         scanf("%d", a);
         ^
    

提交回复
热议问题