【问题标题】:Segmentation fault (core dumped) in C [duplicate]C中的分段错误(核心转储)[重复]
【发布时间】:2017-08-17 12:51:50
【问题描述】:

这是一个检查闰年的程序。你能告诉我为什么会出现这个错误吗?

#include <stdio.h>

int main()
{
    int year=0;
    printf("Enter the year  to be Validated \n");
    scanf("%d",year);
    if (year%4==0){
        printf ("one");
        if (year%100==0){
            printf ("two");
            if (year%400==0){
                printf("Leap Year");
            }
                else{
                    printf("Non Leap year");


            }}}

  return 0;
}

【问题讨论】:

标签: c


【解决方案1】:

您必须将指针传递给scanf

scanf("%d",year);

应该是

scanf("%d", &year);

【讨论】:

  • @HardipinderSingh 如果有帮助,请考虑接受答案;)
  • 对不起,我不知道我应该这样做。谢谢:) @AnderBiguri
猜你喜欢
  • 2016-01-08
  • 1970-01-01
  • 2019-03-14
  • 2022-01-14
  • 2017-02-25
  • 2016-07-12
  • 2018-03-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多