不同的输出不同的编译器 - C和C ++ [英] Different output for different compiler - C and C++

查看:129
本文介绍了不同的输出不同的编译器 - C和C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你能想到'程序',这给了一个C和C ++编译器不同的输出'的(还给出了同样的语言下,一致的输出)?

Can you think of 'a program' which gives 'different outputs for a C and a C++ compilers' (yet gives consistent output under the same language)?

推荐答案

这个程序产生 12 C ++或C99,和 6 在C89:

This program produces 12 in C++ or C99, and 6 in C89:

#include <stdio.h>

int main()
{
    int a = 12//**/2;
    ;

    printf("%d\n", a);
    return 0;
}

这篇关于不同的输出不同的编译器 - C和C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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