码迷,mamicode.com
首页 > 编程语言 > 详细

c++开始学习2

时间:2017-06-18 15:07:17      阅读:222      评论:0      收藏:0      [点我收藏+]

标签:管理   同名   重载   struct   amp   基本类型   ++   delete   typedef   

慕课学习C++远征之离港篇

1、引用

 基本类型引用:int a = 3; int &b = a;

 结构体类型引用:typedef struct { int x; int y;}Coor;

         Coor c1; Coor &c = c1; c.x = 10; c.y = 20; cout << c1.x << c1.y;

 指针类型引用:int a = 10; int *p = &a; int *&q = p; *q = 20; cout << a << endl;

 函数引用:fun(int &a, int &b){ }   

      int x = 10, int y = 20;

        fun(x, y)

2、const

 基本类型:const int a = 10; // a为常量

 指针:const int *p = NULL; int const *p = NULL; 等价

    int * const p = NULL;

    const int * const p = NULL; int const * const p = NULL; 等价

 引用:int x = 10; const int &y = x; // x = 20;正确     // y = 20;错误

3、函数特性

 默认值,函数重载(同名函数),内联函数

4、内存管理

 申请:new,new *p = new int; new *arr = new int[10];块内存申请与释放。申请要判断是否为空(空为错)

 释放:delete,delete p; delete []arr; 释放要设空指针

c++开始学习2

标签:管理   同名   重载   struct   amp   基本类型   ++   delete   typedef   

原文地址:http://www.cnblogs.com/kekeximi/p/7044286.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!