小编PO_*_*PO_的帖子

“大多数 C 系统提供逻辑上无限的浮动值”是什么意思?

最初我将变量 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

我不明白这里发生了什么。 …

c precision divide-by-zero format-specifiers

3
推荐指数
1
解决办法
71
查看次数

一个程序在不同的编译器上的行为会不同吗?

 #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。
请解释一下,这里发生了什么?
谢谢你

c arrays

0
推荐指数
1
解决办法
84
查看次数

标签 统计

c ×2

arrays ×1

divide-by-zero ×1

format-specifiers ×1

precision ×1