c语言sizeof和strlen的使用对比区别

1,sizeof举例:

#include

int main()
{
	char str[] = "hello word";
	char str1[] = {'h','e','l','l','o'};
	char *str2 = "hello word";
	char str3[][20] = {"hello","word","nihao"}; //3 array
	char str4[] = {'h','e','l','l','\0','o'};

	printf("sizeof(str)= %ld\n",sizeof(str));
	printf("sizeof(str1)= %ld\n",sizeof(str1));
	printf("sizeof(str2)= %ld\n",sizeof(str2));
	printf("sizeof(str3)= %ld\n",sizeof(str3));
	printf("sizeof(str3+0)= %ld\n",sizeof(*(str3+0)));
	printf("sizeof(str3+1)= %ld\n",sizeof(*(str3+1)));
	printf("sizeof(str3+2)= %ld\n",sizeof(*(str3+2)));
	printf("sizeof(str4)= %ld\n",sizeof(str4));
	return 0;
}

c语言sizeof和strlen的使用对比区别_第1张图片

2,strlen的使用举例:

#include
#include

你可能感兴趣的:(c语言基础)