首页 > 其他 > 详细

sizeof与strlen

时间:2019-11-23 21:48:14      阅读:86      评论:0      收藏:0      [点我收藏+]

#include <stdio.h>
#include <string.h>
#include<stdlib.h>
void testArr(const char str[])
{
printf("%lu %lu\n", sizeof(str), strlen(str));
}
int main(void)
{

char str[] = "hello";
printf("test0 %lu %lu\n\n", sizeof(str), strlen(str));


char str1[8] = "hello";
printf("test1 %lu %lu\n\n", sizeof(str1), strlen(str1));


char str2[] = { ‘h‘,‘e‘,‘l‘,‘l‘,‘o‘ };
printf("test2 %lu %lu\n\n", sizeof(str2), strlen(str2));


char *str3 = "hello";
printf("test3 %lu %lu\n\n", sizeof(str3), strlen(str3));


char str4[] = "hello";
testArr(str4);


char str5[] = "hell\0o";
printf("test5 %lu %lu\n", sizeof(str5), strlen(str5));


char str6[10] = { 0 };
printf("test6 %lu %lu\n\n", sizeof(str6), strlen(str6));


char str8[5] = { 0 };
strncpy(str8, "hello", 5);
printf("%s\n", str8);
system("pause");
return 0;
}

 

技术分享图片

 

sizeof与strlen

原文:https://www.cnblogs.com/tiange-137/p/11919599.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!