#include <iostream>
using namespace std;
void func(char arg[])
{
cout<<sizeof(arg)<<endl;
}
int main()
{
char str[] = "hello";
cout<<strlen(str)<<endl;
cout<<sizeof(str)<<endl;
char *p = str;
cout<<sizeof(p)<<endl;
func(p);
return 0;
}
在x64
依次输出:5,6,8,8
在w32
5,6,4,4,
sizeof(a)
返回a这个数据的所占的内存大小,以字节为单位
str最后有一个'\0'
但是sizeof(p),因为p是指针,所以返回指针所占大小,就是和Int一样的大小
在形参上,即使是数组的形式,但是在编译器还是把它翻译成指针