sizeof与strlen
Posted tiange-137
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sizeof与strlen相关的知识,希望对你有一定的参考价值。
#include <stdio.h>
#include <string.h>
#include<stdlib.h>
void testArr(const char str[])
{
printf("%lu %lu
", sizeof(str), strlen(str));
}
int main(void)
{
char str[] = "hello";
printf("test0 %lu %lu
", sizeof(str), strlen(str));
char str1[8] = "hello";
printf("test1 %lu %lu
", sizeof(str1), strlen(str1));
char str2[] = { ‘h‘,‘e‘,‘l‘,‘l‘,‘o‘ };
printf("test2 %lu %lu
", sizeof(str2), strlen(str2));
char *str3 = "hello";
printf("test3 %lu %lu
", sizeof(str3), strlen(str3));
char str4[] = "hello";
testArr(str4);
char str5[] = "hell o";
printf("test5 %lu %lu
", sizeof(str5), strlen(str5));
char str6[10] = { 0 };
printf("test6 %lu %lu
", sizeof(str6), strlen(str6));
char str8[5] = { 0 };
strncpy(str8, "hello", 5);
printf("%s
", str8);
system("pause");
return 0;
}
以上是关于sizeof与strlen的主要内容,如果未能解决你的问题,请参考以下文章