eg:
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char name[] = "hello";//这句话的意思是:现在将常量区(就是编译阶段就已经给hello\0这个字符串分配了内
//存)的字符串hello\0拷贝一份,来初始化在栈区定义的字符数组name,这个字符
//数组中存放了 hello\0 6个字符
printf("%d\n",sizeof(name));
printf("%d\n",strlen(name));
system("pause");
return EXIT_SUCCESS;
}
本文介绍了一个简单的C语言程序,演示了如何使用字符数组存储字符串,并通过sizeof和strlen函数展示字符串长度的不同计算方式。

被折叠的 条评论
为什么被折叠?



