char c[] = "abcde";
cout << sizeof(c)<<endl; //output 6
cout << strlen(c) << endl;//output 5
------------------------------------------------
char c[10] = "abcde";
cout << sizeof(c)<<endl; //output 10
cout << strlen(c) << endl;//output 5
------------------------------------------------
//数组作为参数传给函数时传的是指针而不是数组,传递的是数组的首地址
char c[10] = "abcde";
void Print(char ch[])//等价于 fun(char *)
{
cout << sizeof(ch) << endl; //output 4
cout << strlen(ch) << endl;//output 5
}
void Print(char ch[5])//等价于 fun(char *)
{
cout << sizeof(ch) << endl; //output 4
cout << strlen(ch) << endl;//output 5
}
void Print(char* ch)
{
cout << sizeof(ch) << endl; //output 4
cout << strlen(ch) << endl;//output 5
}
------------------------------------------------
char*c = "abcde";
cout << sizeof(c)<<endl;//output 4 (pointer)
cout << strlen(c) << endl;//output 5
------------------------------------------------
int i[4];
cout << sizeof(i)<<endl; //output 16
cout << sizeof(i)/sizeof(i[0])<<endl;//output 4
------------------------------------------------
char Array[3] = {'0'};
sizeof(Array) == 3;
char *p = Array;
strlen(p) == 1;//sizeof(p)结果为4
------------------------------------------------
char c[]="a\n";
cout << sizeof(c) << endl;//output 3 //'\n' is one char
cout << strlen(c) << endl;//output 2 //'\n' is one char
------------------------------------------------
class X
{ int i; int j; char k;};
X x;
cout<<sizeof(X)<<endl; //结果 12 (内存补齐)
cout<<sizeof(x)<<endl; //结果 12 同上
------------------------------------------------
char c[5] = "abcde"; //error
------------------------------------------------