不使用 &scanf() 中的变量是语法错误还是运行时错误? [英] Is not using & with a variable in scanf() a syntax error or a runtime error?
问题描述
有人告诉我语法错误来自一个错误并且不执行程序.但是,运行时错误仍会启动程序,但会在中间崩溃.如果我在调用 scanf()
时不小心没有将 &
放在变量前面,那会被认为是语法错误还是运行时错误?
I was taught that a syntax error comes from a single mistake and doesn't execute the program. However, a runtime error still starts the program but crashes in the middle. If I accidentally didn't put &
in front of a variable in a call to scanf()
, would that considered to be a syntax error or a runtime error?
例如
int main(void)
{
int a;
printf("input a integer number >>");
scanf("%d\n", a);
printf("the input number is %d\n", a);
return 0;
}
在 scanf
语句中,我在 a
前面没有 &
这样会崩溃,但它仍然执行第一个 printf
语句,所以它会显示一些打印的文本.
In the scanf
statement, I don't have &
in front of a
so that would crash,
but it still executes the first printf
statement, so it would show some printed text.
它会同时是运行时错误和语法错误吗?
Is it going to be both a runtime error and a syntax error?
推荐答案
这篇关于不使用 &scanf() 中的变量是语法错误还是运行时错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!