我是一名学习 C 的 Python 程序员。我在以下代码的最终 printf()
中收到段错误。我确定它与表达式有关,但我不确定问题出在哪里。不幸的是,该表达式在 Python 中有效,所以我无法获得更具体的错误消息。我在 Debian 中使用 GCC 编译器。
#include <stdio.h>
int main(void)
{
int n;
printf("Enter a two-digit number: ");
scanf("%d",n);
printf("The reversal is: %d\n", (n % 10) * 10 + (n / 10));
return 0;
}
最佳答案
将n
的地址传递给scanf()
作为
scanf("%d", &n);
关于c - 为什么我会收到以下代码的段错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20112048/