第四章指针与数组
2014-06-19 22:48
267 查看
每一个程序在执行时都占用一个可用的内存空间,用于存放动态分配的对象,此内存空间称为程序的自由存储区或堆。
c语言使用malloc和free,c++使用new和delete来实现在自由存储区分配和回收内存;
string *psa=new string[10];//类类型,使用默认构造
int *pia=new int[10];//值类型,无初始化
int *pia2=new int[10]();//初始化为0
const int *pci_bad=new const int[100];//错误,无初始化同时不能修改值
cosnt int *pci_ok=new const int[100]();//初始化为0,不可修改
const string *pcs=new const string[100];//无意义,都是空串
char arr[0];//错误
char *cp=new char[0];//正确,但是cp不可以解引用,只可以:比较运算
指针数组:array of pointers,即用于存储指针的数组,也就是数组元素都是指针
数组指针:a pointer to an array,即指向数组的指针
int* a[4] 指针数组
表示:数组a中的元素都为int型指针
元素表示:*a[i] *(a[i])是一样的,因为[]优先级高于*
int (*a)[4] 数组指针
表示:指向数组a的指针
元素表示:(*a)[i]
typedef int int_array[4];
int_array *ip=0;
c语言使用malloc和free,c++使用new和delete来实现在自由存储区分配和回收内存;
string *psa=new string[10];//类类型,使用默认构造
int *pia=new int[10];//值类型,无初始化
int *pia2=new int[10]();//初始化为0
const int *pci_bad=new const int[100];//错误,无初始化同时不能修改值
cosnt int *pci_ok=new const int[100]();//初始化为0,不可修改
const string *pcs=new const string[100];//无意义,都是空串
char arr[0];//错误
char *cp=new char[0];//正确,但是cp不可以解引用,只可以:比较运算
指针数组:array of pointers,即用于存储指针的数组,也就是数组元素都是指针
数组指针:a pointer to an array,即指向数组的指针
int* a[4] 指针数组
表示:数组a中的元素都为int型指针
元素表示:*a[i] *(a[i])是一样的,因为[]优先级高于*
int (*a)[4] 数组指针
表示:指向数组a的指针
元素表示:(*a)[i]
typedef int int_array[4];
int_array *ip=0;
相关文章推荐
- 第四章 数组和指针
- 第四章 数组和指针 (part4) 多维数组
- 第四章 初始化动态分配的数组,以及指针与多维数组
- 第四章 数组,字符串和指针
- C++primer第四章(二):数组和指针——指针
- 第四章:数组和指针
- C++primer学习笔记第四章-数组与指针
- 第四章 数组,字符串和指针
- C++ Primer复习和学习笔记 第四章 数组和指针
- C总结-第四章 指针数组(4/6)
- (笔记)C++ Primer/第四章 数组和指针
- C++ Primer 第四章 数组与指针
- 《C专家编程》第四章——令人震惊的事实:数组和指针并不相同
- 【重学《C++Primer第四版》】第四章、数组和指针
- 第四章数组和指针(数组)
- 第四章数组与指针(指针)
- 第四章作业:4.17:建立一个对象数组,内放6个学生的数据(学号,成绩),用指针向数组首元素,输出第2,4,6个学生的数据。
- 《c++ primer》第四章--数组和指针
- 第四章 数组和指针 (part1) 数组
- 第四章 数组和指针(part5) 总结 & 常用术语