在C89模式下编译时,下面的程序如何输出C89;在C99模式下编译时,下面的程序如何输出? [英] How does the below program output `C89` when compiled in C89 mode and `C99` when compiled in C99 mode?

查看:102
本文介绍了在C89模式下编译时,下面的程序如何输出C89;在C99模式下编译时,下面的程序如何输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经从网上找到了这个C程序:

I've found this C program from the web:

#include <stdio.h>

int main(){

    printf("C%d\n",(int)(90-(-4.5//**/
    -4.5)));

    return 0;
}

此程序的有趣之处在于,它在C89中编译并运行时模式,它会打印 C89 ,并且在以C99模式编译并运行时,它会打印 C99 。但是我无法弄清楚这个程序是如何工作的。

The interesting thing with this program is that when it is compiled and run in C89 mode, it prints C89 and when it is compiled and run in C99 mode, it prints C99. But I am not able to figure out how this program works.

您能解释一下 printf 的第二个参数吗?

Can you explain how the second argument of printf works in the above program?

推荐答案

C99允许 // 样式吗?评论,C89没有。因此,要翻译为:

C99 allows //-style comments, C89 does not. So, to translate:

C99:

 printf("C%d\n",(int)(90-(-4.5     /*Some  comment stuff*/
                         -4.5)));
// Outputs: 99

C89:

printf("C%d\n",(int)(90-(-4.5/      
                         -4.5)));
/* so  we get 90-1 or 89 */

这篇关于在C89模式下编译时,下面的程序如何输出C89;在C99模式下编译时,下面的程序如何输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆