size计算的值为所有空间的大小
strlen计算的值为实际字符数
需要添加头文件#include <string.h>
#include<stdio.h>
#include<string.h>
void test()
{
}
int main()
{
char cdata[128]="hello";
void (*ptest)();
ptest=test;
//如果[]为空值,结果为6,包含结束符'\0'
printf ("sizeof:%d\n",sizeof(cdata));//结果为128,开辟的空间为128个,其他为\0
printf ("strlen:%d\n",strlen(cdata));//结果为5,为实际字符位数
char *p="hello";
//p是一个char *,sizeof来计算的时候,得出是计算机用多少字节来表示一个地址
printf ("sizeof:%d\n",sizeof(p));//结果为8,
printf ("sizeof:%d\n",sizeof(char *));//结果为8
printf ("sizeof:%d\n",sizeof(int *));//结果为8,所有指针都是8字节来存储
printf ("sizeof:%d\n",sizeof(int));//int类型结果为4
printf ("sizeof:%d\n",sizeof(char));//char类型结果为1
printf ("sizeof:%d\n",sizeof(test));//结果为1
printf ("sizeof:%d\n",sizeof(ptest));//函数指针,结果为8
printf ("strlen:%d\n",strlen(p));//结果为5,计算实际字符位数
return 0;
}