指针
char *b = "helloworld";
char *c[10];
double *d;
int **e;
cout << "char *b=" << sizeof(b) << endl;//指针指向字符串,值为4
cout << "char *b=" << sizeof(*b) << endl; //指针指向字符,值为1
cout << "double *d=" << sizeof(d) << endl;//指针,值为4
cout << "double *d=" << sizeof(*d) << endl;//指针指向浮点数,值为8
cout << "int **e=" << sizeof(e) << endl;//指针指向指针,值为4
cout << "char *c[10]=" << sizeof(c) << endl;//指针数组,数组c中的元素都为char型指针,值为4×10 = 40
数组
int a[5]
cout << sizeof(a) << '\n'; //规定了大小 就按照大小来,输出为5×4 = 20
char str1[5] = "hi";
cout << sizeof(str1) << '\n'; //规定了大小 就按照大小来,输出为5
char str2[] = "hi";
cout << sizeof(str2) << '\n'; //没有规定大小,就按照字符的个数 但是末尾会有/n,输出3
char str3[] = { 'a', 'b', 'c', 'd' };
cout << sizeof(str3) << '\n'; //没有规定大小,输出4
char str4[10] = { 'a', 'b', 'c', 'd' };
cout << sizeof(str4) << '\n'; //规定了大小,就按照大小来,输出为10
char str5[] = { 'a', 'b', 'c', 'd', '\0', 't',' ','u' };
cout << sizeof(str5) << '\n'; //等于8 中间的'\0'不受影响,' '也不受影响
cout << strlen(str5) << '\n'; //等于4 只计算到'\0'前
数组作为函数参数
32位系统指针的大小为4,64位系统指针的大小为8
void func(char a[3])
{
int c = sizeof(a); //c = 4,因为这里a不在是数组类型,而是指针,相当于char *a。
}
void funcN(char b[])
{
int cN = sizeof(b); //cN = 4,理由同上。
}