一、C++简介
1、c++语法特性?
c++是一种面向对象的语言,任何一个事情都是某一个对象上的行为和属性
2.C++语法
c++继承了c语言的语法之外,还拓展了数据类型,继承、多态等新语法
3.C++函数接口
C++提供了标准模板库(STL),它里面提供了一些通用的接口,全世界的人都使用一个接口
二、书写第一个C++程序
1.创建一个c++的工程的文件
C++ 工程文件的格式 xxx.cpp (c++ plus plus)
2.比那及代码
1)C++是兼容c的,也是从main开始,从main结束
2)如果要使用c++ 语法必须要包含标准头文件以及对应的命名空间
#include<iostream> ----标准头文件
using namespace std; ----标准的命名空间
(在c++中有很多的工具都是放在这个命名空间中,如果你想在C++的代码中直接使用这些工具,那么就必须使用我们的标准的命名空间)
(如果不使用命名空间,那么你使用工具时,就必须在工具前面加作用于符号)
3)c++中使用cout这个工具来输出
4)endl 相当于“\n”
  
   - 
    
     
    
    
     
      #include<iostream>
     
    
 
   - 
    
     
    
    
     
      using 
      namespace 
      std:
     
    
 
   - 
    
     
    
    
     
      int main(int argc ,char*argv[]){
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
         
      cout << 
      "hellowworld" <<
      endl;
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
         
      return 
      0
     
    
 
   - 
    
     
    
    
     
      }
     
    
 
  
 
5)编译
g++ 1.cpp -o 1
三、变量
1.变量的作用
给一段指定的内存空间起一个名字,方便我们去操作他
2.如何在C++程序中输出一个变量的值
  
   - 
    
     
    
    
     
      #include<iostream>
     
    
 
   - 
    
     
    
    
     
      using 
      namespace 
      std;
     
    
 
   - 
    
     
    
    
     
      int main(int argc ,char*argv[]){
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
         
      cout << 
      "hellowworld" <<
      endl;
     
    
 
   - 
    
     
    
    
         
     
    
 
   - 
    
     
    
    
         
      int a =
      10;
     
    
 
   - 
    
     
    
    
         
      cout<<
      "a="<<a<<
      endl;
     
    
 
   - 
    
     
    
    
         
      return 
      0;
     
    
 
   - 
    
     
    
    
     
      }
     
    
 
  
 
四、常量。
1、常量的作用? 用于记录程序中不可修改的数据。
2、C++定义常量方法有两种:
1)宏常量。
  
   - 
    
     
    
    
     
      #include <iostream>
     
    
 
   - 
    
     
    
    
     
      using 
      namespace 
      std;
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
     
      #define DAY 7
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
     
      int main(int argc, char *argv[])
     
    
 
   - 
    
     
    
    
     
      {
     
    
 
   - 
    
     
    
    
         
      cout << 
      "一个星期有:" << DAY << 
      "天" << 
      endl;
     
    
 
   - 
    
     
    
    
         
      return 
      0;
     
    
 
   - 
    
     
    
    
     
      }
     
    
 
  
 
2)const修饰的变量。
  
   - 
    
     
    
    
     
      #include <iostream>
     
    
 
   - 
    
     
    
    
     
      using 
      namespace 
      std;
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
     
      int main()
     
    
 
   - 
    
     
    
    
     
      {
     
    
 
   - 
    
     
    
    
         
      const 
      int month = 
      12; 
      //变量
     
    
 
   - 
    
     
    
    
         
      //month = 13;
     
    
 
   - 
    
     
    
    
         
      cout << 
      "一年有:" << month << 
      "月" << 
      endl;
     
    
 
   - 
    
     
    
    
         
      return 
      0;
     
    
 
   - 
    
     
    
    
     
      }
     
    
 
  
 
五、字符串
1.在C++中有两种风格可以表示字符串
C风格的字符串:
语法:char 数组名[]=“字符串的值”
C++风格字符串:
语法: string字符串名=“字符串值”
  
   - 
    
     
    
    
     
      #include <iostream>
     
    
 
   - 
    
     
    
    
     
      using 
      namespace 
      std;
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
     
      int main()
     
    
 
   - 
    
     
    
    
     
      {   
     
    
 
   - 
    
     
    
    
         
      char b[]=
      "aaaaaa";
     
    
 
   - 
    
     
    
    
         
      string a = 
      "ghjad";
     
    
 
   - 
    
     
    
    
         
      cout << a << 
      endl;
     
    
 
   - 
    
     
    
    
         
      cout << b << 
      endl;
     
    
 
   - 
    
     
    
    
         
      return 
      0;
     
    
 
   - 
    
     
    
    
     
      }
     
    
 
  
 
六、转义符号
常用的转移符号:
“\n” ---换行
“\t” ----水平制表,跳转到下一个tab键的位置
  
   - 
    
     
    
    
     
      #include <iostream>
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
     
      using 
      namespace 
      std;
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
     
      int main()
     
    
 
   - 
    
     
    
    
     
      {
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
         
      cout << 
      "helloe\n";
     
    
 
   - 
    
     
    
    
         
      cout << 
      "aaaaa\thelloe\n";
     
    
 
   - 
    
     
    
    
         
      cout << 
      "aaa\thelloe\n";
     
    
 
   - 
    
     
    
    
         
      cout << 
      "a\thelloe\n";
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
             
      return 
      0;
     
    
 
   - 
    
     
    
    
     
      }
     
    
 
  
 

七、数据的输入
1.作用:从键盘获取一些数据
2.关键词:cin
  
   - 
    
     
    
    
     
      #include <iostream>
     
    
 
   - 
    
     
    
    
     
      using 
      namespace 
      std;
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
     
      int main()
     
    
 
   - 
    
     
    
    
     
      {
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
         
      string a;
     
    
 
   - 
    
     
    
    
         
      int b;
     
    
 
   - 
    
     
    
    
         
      double c;
     
    
 
   - 
    
     
    
    
         
      cin >> a >> b >> c;
     
    
 
   - 
    
     
    
    
         
      cout << a << 
      endl
     
    
 
   - 
    
     
    
    
     
               << b << 
      endl
     
    
 
   - 
    
     
    
    
     
               << c << 
      endl;
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
         
      return 
      0;
     
    
 
   - 
    
     
    
    
     
      }
     
    
 
  
 
另外c++ 的cin会自动清除缓存区,不需要担心缓存区 有留存东西
八、递增递减运算符
1.作用::变量自身 +1/-1
2.符号 : ++/--
在C++中不支持连续的后置递增:(a++)++
九、比较运算符:
==、!=、<、>、<=、>=
  
   - 
    
     
    
    
     
      #include "iostream"
     
    
 
   - 
    
     
    
    
     
      using 
      namespace 
      std;
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
     
      int main()
     
    
 
   - 
    
     
    
    
     
      {
     
    
 
   - 
    
     
    
    
         
      string a = 
      "aaa";
     
    
 
   - 
    
     
    
    
         
      string b = 
      "aaabbbb";
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
         
      cout<<(a==b)<<
      endl;
     
    
 
   - 
    
     
    
    
         
      cout<<(a!=b)<<
      endl;
     
    
 
   - 
    
     
    
    
         
      cout<<(a>=b)<<
      endl;
     
    
 
   - 
    
     
    
    
         
      cout<<(a<=b)<<
      endl;
     
    
 
   - 
    
     
    
    
         
      cout<<(a>b)<<
      endl;
     
    
 
   - 
    
     
    
    
         
      cout<<(a<b)<<
      endl;
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
         
      if (a == b)
     
    
 
   - 
    
     
    
    
     
          {
     
    
 
   - 
    
     
    
    
             
      cout << 
      1 << 
      endl;
     
    
 
   - 
    
     
    
    
     
          }
     
    
 
   - 
    
     
    
    
         
      else
     
    
 
   - 
    
     
    
    
     
          {
     
    
 
   - 
    
     
    
    
             
      cout << 
      2 << 
      endl;
     
    
 
   - 
    
     
    
    
     
          }
     
    
 
   - 
    
     
    
    
         
      return 
      0;
     
    
 
   - 
    
     
    
    
     
      }
     
    
 
  
 

结论:
字符串比较大小、按照ascll依次一一比较
十、逻辑运算符
1.根据表达式真假,返回真或者假
2.符号
!、&&、||、
  
   - 
    
     
    
    
     
      #include <iostream>
     
    
 
   - 
    
     
    
    
     
      using 
      namespace 
      std;
     
    
 
   - 
    
     
    
    
     
      int main()
     
    
 
   - 
    
     
    
    
     
      {
     
    
 
   - 
    
     
    
    
         
      int a = 
      10;
     
    
 
   - 
    
     
    
    
         
      int b = 
      10;
     
    
 
   - 
    
     
    
    
         
      int c = 
      0;
     
    
 
   - 
    
     
    
    
         
      int d = 
      0;
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
         
      cout << !a << 
      endl;
     
    
 
   - 
    
     
    
    
         
      cout << !!a << 
      endl;
     
    
 
   - 
    
     
    
    
         
      cout << (a&&b) << 
      endl;
     
    
 
   - 
    
     
    
    
         
      cout << (a||b) << 
      endl;
     
    
 
   - 
    
     
    
    
         
      cout << (a&&c) << 
      endl;
     
    
 
   - 
    
     
    
    
         
      cout << (a||c) << 
      endl;
     
    
 
   - 
    
     
    
    
         
      cout << (c||d) << 
      endl;
     
    
 
   - 
    
     
    
    
         
      cout << (c&&d) << 
      endl;
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
         
      return 
      0;
     
    
 
   - 
    
     
    
    
     
      }
     
    
 
  
 

十一、内存分区模型
1.在C++程序执行时,将内存大致方向分为四个区域
1)代码区:存放着函数的二进制代码,由操作系统进行管理
2)全局区:存放着全局变量,静态变量、常量
3)堆区:由工程师手动分配与释放、如果不释放,程序结束由系统自动回收。(new、malloc、calloc)
4)栈区:由编译器自动分配和释放、存放的时函数形式参数、局部变量。
2.内存四区的意义?
不同的区域存放不同的数据,赋予它不同的生命周期,给我们更大的灵活编程
十二、程序运行前
在程序编译后,生成一个可执行文件,未执行这个程序之前分为两个区域
1、代码区:
存放CPU执行的机器指令 -> 其实就是指0101这种数据。
代码区是共享的,共享的目的是对于频繁被执行的代码,只需要在内存中有一份代码即可。 无论执行了多少次这段代码,都是使用同一个代码。
代码区是只读的,使其只读的原因是防止程序意外地修改它的指令。
2、全局区:
全局变量与静态变量存放在此。
全局区还包含了常量区、字符串常量、其他常量(const修改的变量)在存放在此。
该区域的数据在程序结束之后由操作系统来释放。
  
   - 
    
     
    
    
     
      #include <iostream>
     
    
 
   - 
    
     
    
    
     
      using 
      namespace 
      std;
     
    
 
   - 
    
     
    
    
     
      int g_a = 
      10;
     
    
 
   - 
    
     
    
    
     
      int g_b = 
      20;
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
     
      const 
      int c_g_a = 
      10;
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
     
      int main()
     
    
 
   - 
    
     
    
    
     
      {
     
    
 
   - 
    
     
    
    
         
      int a;
     
    
 
   - 
    
     
    
    
         
      static 
      int s_a = 
      10;
     
    
 
   - 
    
     
    
    
         
      const 
      int c_l_a = 
      10;
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
         
      //栈区
     
    
 
   - 
    
     
    
    
         
      cout << &a << 
      endl;     
      //局部变量
     
    
 
   - 
    
     
    
    
         
      cout << &c_l_a << 
      endl; 
      //const修饰的局部变量-----局部常量
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
         
      //全局区
     
    
 
   - 
    
     
    
    
         
      cout << &g_a << 
      endl;                          
      //全局变量
     
    
 
   - 
    
     
    
    
         
      cout << &g_b << 
      endl;                          
      //全局变量
     
    
 
   - 
    
     
    
    
         
      cout << &s_a << 
      endl;                          
      //静态变量
     
    
 
   - 
    
     
    
    
         
      cout << 
      "string address:" << &
      "fhasj" << 
      endl; 
      //字符串常量
     
    
 
   - 
    
     
    
    
         
      cout << &c_g_a << 
      endl;                        
      //const修饰的全局变量-----全局常量
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
         
      //
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
         
      return 
      0;
     
    
 
   - 
    
     
    
    
     
      }
     
    
 
  
 

结论:
栈区:
局部变量
const修饰的局部变量(局部常量)
在全局区
全局变量
静态变量
常量
const修饰的全局变量(全局常量)
十三、程序运行后
栈区: 由编译器自动分配释放。存放的函数的形式参数、局部变量等
注意: 不要返回局部变量的地址
堆区:由工程师手动分配与释放、如果不释放,程序结束由系统自动回收。
在C++中主要利用new堆区开辟空间
  
   - 
    
     
    
    
     
      #include <iostream>
     
    
 
   - 
    
     
    
    
     
      using 
      namespace 
      std;
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
     
      int *func()
     
    
 
   - 
    
     
    
    
     
      {
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
         
      //利用new关键词、将数据开辟到堆取
     
    
 
   - 
    
     
    
    
         
      int *p = 
      new 
      int(
      10);
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
         
      return p;
     
    
 
   - 
    
     
    
    
     
      }
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
     
      int main()
     
    
 
   - 
    
     
    
    
     
      {
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
         
      int *p = func();
     
    
 
   - 
    
     
    
    
         
      cout << (*p) << 
      endl;
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
         
      return 
      0;
     
    
 
   - 
    
     
    
    
     
      }
     
    
 
  
 
结论:在函数返回的时候,堆区的空间不会释放
十四、new操作符。
C++中利用new操作符在堆区开辟数据。 堆区中开辟的数据,由工程师手动开辟,手动释放、释放利用操作符delete。
语法:new 数据类型 利用new创建的数据,会返回该数据对应类型的指针。
1、 堆区的基本语法示例。
  
   - 
    
     
    
    
     
      #include <iostream>
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
     
      using 
      namespace 
      std;
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
     
      int *func()
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
     
      {
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
         
      //在堆区中创建整型数据。
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
         
      int *p = 
      new 
      int(
      10);
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
         
      return p;
     
    
 
   - 
    
     
    
    
     
      }
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
     
      int main()
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
     
      {
     
    
 
   - 
    
     
    
    
         
      int p = func();
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
         
      cout << 
      "p = " << *p << 
      endl; 
      //10
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
         
      //堆区的数据由用户主动释放。
     
    
 
   - 
    
     
    
    
         
      delete p;
     
    
 
   - 
    
     
    
    
     
          p = 
      NULL;
     
    
 
   - 
    
     
    
    
     
          
     
    
 
   - 
    
     
    
    
         
      cout << 
      "*p = " << *p << 
      endl; 
      //段错误
     
    
 
   - 
    
     
    
    
     
           
      return 
      0;
     
    
 
   - 
    
     
    
    
     
      }
     
    
 
  
 
2.在堆区利用new开辟数组
  
   - 
    
     
    
    
     
      #include <iostream>
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
     
      using 
      namespace 
      std;
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
     
      int main()
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
     
      {
     
    
 
   - 
    
     
    
    
         
      int *arr = 
      new 
      int[
      10];
     
    
 
   - 
    
     
    
    
         
      int i;
     
    
 
   - 
    
     
    
    
         
      for (i = 
      0; i < 
      10; i++)
     
    
 
   - 
    
     
    
    
     
          {
     
    
 
   - 
    
     
    
    
     
              arr[i] = i + 
      100;
     
    
 
   - 
    
     
    
    
     
          }
     
    
 
   - 
    
     
    
    
         
      for (i = 
      0; i < 
      10; i++)
     
    
 
   - 
    
     
    
    
     
          {
     
    
 
   - 
    
     
    
    
             
      cout << arr[i] << 
      endl; 
      //10
     
    
 
   - 
    
     
    
    
     
          }
     
    
 
   - 
    
     
    
    
         
      delete[] arr;
     
    
 
   - 
    
     
    
    
         
      return 
      0;
     
    
 
   - 
    
     
    
    
     
      }
     
    
 
  
 
十五、引用的基本使用
1.引用作用:
给变量起别名
2.语法:
数据类型 &别名=原名
  
   - 
    
     
    
    
     
      #include <iostream>
     
    
 
   - 
    
     
    
    
     
      using 
      namespace 
      std;
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
     
      int main()
     
    
 
   - 
    
     
    
    
     
      {
     
    
 
   - 
    
     
    
    
         
      int a = 
      10;
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
         
      int &b = a;
     
    
 
   - 
    
     
    
    
         
      cout << b << 
      endl;
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
     
          b=
      100;
     
    
 
   - 
    
     
    
    
         
      cout << b << 
      endl;
     
    
 
   - 
    
     
    
    
         
      cout << a << 
      endl;
     
    
 
   - 
    
     
    
    
         
      return 
      0;
     
    
 
   - 
    
     
    
    
         
      //注意应用对象必须初始化 
     
    
 
   - 
    
     
    
    
     
      }
     
    
 
  
 
注意 1).引用必须初始化
2) 引用在初始化之后。不可以改变,即b永远都是a的别名了
十七、引用做函数的参数
作用:函数传参时,我们可以利用引用 的技术让形参修饰实参、
优点: 可以简化指针修饰实参的方法、
  
   - 
    
     
    
    
     
      #include <iostream>
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
     
      using 
      namespace 
      std;
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
     
      void fun(int &a, int &b)
     
    
 
   - 
    
     
    
    
     
      {
     
    
 
   - 
    
     
    
    
         
      //这个a虽然是一个形参,但是实际上代表的是一个实参
     
    
 
   - 
    
     
    
    
         
     
    
 
   - 
    
     
    
    
         
      int tmp = a;
     
    
 
   - 
    
     
    
    
     
          a = b;
     
    
 
   - 
    
     
    
    
     
          b = tmp;
     
    
 
   - 
    
     
    
    
     
      }
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
     
      int main()
     
    
 
   - 
    
     
    
    
     
      {
     
    
 
   - 
    
     
    
    
         
      int a = 
      10;
     
    
 
   - 
    
     
    
    
         
      int b = 
      20;
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
     
          fun(a, b);
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
         
      cout << a << 
      endl;
     
    
 
   - 
    
     
    
    
         
      cout << b << 
      endl;
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
         
      return 
      0;
     
    
 
   - 
    
     
    
    
     
      }
     
    
 
  
 
十八、引用做函数的返回值
作用:引用是可以作为函数的返回值存在的
注意事项:
1)不要返回局部变量的引用
2)函数的调用可以作为左值的存在
  
   - 
    
     
    
    
     
      #include <iostream>
     
    
 
   - 
    
     
    
    
     
      using 
      namespace 
      std;
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
     
      //引用作为函数返回值
     
    
 
   - 
    
     
    
    
     
      //1、 不要返回局部变量的引用。
     
    
 
   - 
    
     
    
    
     
      //2、 函数的调用可以作为左值的存在。
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
     
      //int --> 返回的是10(本体的值)
     
    
 
   - 
    
     
    
    
     
      //int& --> 返回的是a (本体)
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
     
      int &test01()
     
    
 
   - 
    
     
    
    
     
      {
     
    
 
   - 
    
     
    
    
         
      //1、不要返回局部变量的引用。
     
    
 
   - 
    
     
    
    
         
      //int a = 10; //局部变量
     
    
 
   - 
    
     
    
    
         
      static 
      int a = 
      10;
     
    
 
   - 
    
     
    
    
         
      return a; 
      //其实就是返回a的本体。
     
    
 
   - 
    
     
    
    
     
      }
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
     
      int main()
     
    
 
   - 
    
     
    
    
     
      {
     
    
 
   - 
    
     
    
    
         
      int &ret = test01();
     
    
 
   - 
    
     
    
    
         
      cout << 
      "ret = " << ret << 
      endl; 
      //10
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
         
      //2. 函数的调用可以作为左值的存在。
     
    
 
   - 
    
     
    
    
     
          test01() = 
      1000;                 
      //a = 1000
     
    
 
   - 
    
     
    
    
         
      cout << 
      "ret = " << ret << 
      endl; 
      //1000
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
         
      return 
      0;
     
    
 
   - 
    
     
    
    
     
      }
     
    
 
  
 
引用的详细图解

转载:https://blog.csdn.net/weixin_41558261/article/details/116975490