最初我将变量 x 和 y 声明为 int 类型:
#include<stdio.h>
int main(){
int x, y = 0 ;
x = 1 / y;
printf("%d", x);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
程序崩溃(原因很明显)。
现在我将变量 x 和 y 声明为 double:
#include<stdio.h>
int main(){
double x, y = 0 ;
x = 1 / y;
printf("%d", x);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但是输出:0。(为什么?)
然后我在 printf 中将 %d 更改为 %f:
#include<stdio.h>
int main(){
double x, y = 0 ;
x = 1 / y;
printf("%f", x);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出:1.#INF00
我不明白这里发生了什么。 …
#include<stdio.h>
int main(){
char a[] = {80, 65, 84, 84, 69, 82, 78};
int i;
for( i = 0; a[i]; ++i){
printf("%c", a[i]);
}
//printf("%s", a);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我认为这个程序应该抛出一个运行时错误,是的,当我运行 leetcode online IDE 时它确实如此,但是当我运行 Codechef IDE 时它打印了 PATTERN。
请解释一下,这里发生了什么?
谢谢你