1、c++语法检查增强
全局变量检测增强
![11c9fa68e3a01adcb2598307fd742c5f.png](https://i-blog.csdnimg.cn/blog_migrate/51250ff11fb49a92d98d733694d40aeb.jpeg)
![80bae3cc40d74b211a6d90eb9a9f7acc.png](https://i-blog.csdnimg.cn/blog_migrate/ef5c952d9b1a5c7a4e6e81d6a8c7de86.jpeg)
以上c代码c编译器编译可通过,c++编译器无法编译通过
![c6409dcaeba2ce013dd2e7dd73b864d0.png](https://i-blog.csdnimg.cn/blog_migrate/538c739eadf3ce18761be55b72e8814b.jpeg)
2、c++对结构体的增强
1、c中定义结构体变量需要加上struct关键字,c++不需要
2、c中的结构体只能定义成员变量,不能定义成员函数。c++即可以定义成员变量,也可以定义成员函数
C语言:
struct stu{ int num; char name[32];/* c语言 不允许在结构体中 定义成员函数 void func(void) { printf("我是结构体中的func"); } */};void test01(){ //C语言必须加struct struct stu lucy = {100, "lucy"};}
C++语言
struct stu{ int num; char name[32]; //c++语言 允许在结构体中 定义成员函数 void func(void) { printf("我是结构体中的func"); } };void test01(){ //C++语言不用加struct stu lucy = {100, "lucy"}; //调用结构体中的成员方法(成员函数) lucy.func();}
3、c++新增bool类型
![6047aa7c66a44bf253729cad2f8d5be7.png](https://i-blog.csdnimg.cn/blog_migrate/3fe9f3e3a76bc9a75e8dcd66ba76cd14.jpeg)
void test02(){ bool mybool; cout<
4、三目运算符功能增强
1、c语言三目运算表达式返回值为数据值,为右值,不能赋值
void test02(){ int a = 10; int b = 20; printf("C语言:%d", a>b?a:b);//20 //a>b?a:b整体结果 右值(不能被赋值) a>b?a:b = 100;//err不能被赋值}
2、c++语言三目运算表达式返回值为变量本身(引用),为左值,可以赋值
void test02(){ int a = 10; int b = 20; cout<b?a:b)<b?a:b整体结果是变量本身(引用) 左值(能被赋值) a>b?a:b = 100;//b =100}
![4ae8b96d2c12ddbcc88f24d0afcfce31.png](https://i-blog.csdnimg.cn/blog_migrate/496f1a6cf250f18fc8c81be2a12ff20d.jpeg)