写一个只能C编译通过,而C++不能编译通过的函数。

来源:互联网 发布:sql中count 1 的用法 编辑:程序博客网 时间:2024/05/18 01:54

写一个只能C编译通过,而C++不能编译通过的函数。

#include <stdio.h>int main(void){    int new = 5;  // new is a keyword in C++, but not in C    printf("%d", new);}

------对于C++中拥有,C中没有的关键字都可以。eg。delete,try,template,


写一个C,C++运行结果不一样的函数。

(1)C中把char类型作为int型来对待

#include<stdio.h>int main(){  printf("%d", sizeof('a'));  return 0;}


(2)C中没有bool类型

// output = 4 in C (which is size of int)printf("%d", sizeof(1==1));  // output = 1 in c++ (which is the size of boolean datatype)cout << sizeof(1==1); 


0 0
原创粉丝点击