我有以下代码
long x;
scanf("%ld",&x)
if(x==-1) // does this comparison is allowed
printf("just test\n");
long
参数在比较之前是否需要转换?
最佳答案
-1
是十进制的 int
。存在从 int
到 long
的隐式转换(提升),因此 -1
自动“转换”为 long
.
此外,-1
和x
都是有符号类型。不需要任何额外的转换。
关于c - 长比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14978211/