ps:以下各例在c语言中都会报错,但在c++中能正常运行
1.c语言是先定义 再使用,不能边定义 边使用
for(int i = 0; i < 10; ++i)
2.c语言的定义要放在语句之前
int x = 10;
for(int i = 0; i < 10; ++i)
{
}
int y;
y = 100;
3.c语言不支持重载
int max(int a,int b){return a>b?:b;}
double max(double a,double b){return a>b?:b;}
void main()
{
max(1.1,2.2);
}
4.c语言没有命名空间
using namespace std;
5.头文件 文件后缀名 输入输出符
c语音:<stdio.h> .cscanf/printf
c++:<iostream> .cppcin/cout
6.自定义类型:c语言struct c++ class
c语言不允许使用空结构体,不支持class
struct Test{};
ps:如果没用typedef重命名 定义时不能为 Test t;而要为struct Test t;
7.c语言面向过程(function) c++面向对象(object)