C/C++指针

C/C++指针_第1张图片
除Heap外,其余三块都是在应用程序启动时就分配内存。
传引用节省很大内存。
数组与指针:
1.
char c1[20]="test";√//('\0'自动补齐implicit)
char c2;
c2=c1;√
c1=c2;×
c2++;√
c1++;×
2.数组作为引用传递给函数参数;
3.char *C="hello";√ //string gets stored at compile time constant
C[0]='A';× //不能修改
但是可以在functions中修改
void modify(char *c){
c[0]='A';
}
4.name of the array returns the pointer to the first element;(一维数组)
5.int B[2][3];
int *p=B;× //the type of pointer matters not when you have to read the adress,it matters when you dereference or when you perform pointer arithmetic.
The type of pointer play role when you try to dereference or when you try or perform pointer arithmetic;
int (
p)[3]=B;
B[i][j]=*(B[i]+j)=*(*(B+i)+j);
6.Anything on the heap has to be accessed through a pointer variable.

你可能感兴趣的:(cc++指针)