A.sizeof:实际分配空间的大小
int a[2]={1,2}; len=sizeof(a)/sizeof(a[0]);
B.strlen:只针对char类型,且统计到第一个’\0’元素之前
C.char *s = “abc”; //常量不可变
D.char s[maxsize] = “abc” 等价与普通数组
char arr[maxsize]={‘a’,’b’,’c’}
代码:
两个数组完全等价:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXSIZE 100
int main(int argc,char **argv)
{
char ar[10] = "abc";
char s[10]={
'a','b','c'};
s[3] = 'n';
ar[3] = 'n';
printf("%s\n",ar);
printf("%s\n",s);
printf("%d %d\n",sizeof(s),sizeof(ar));
printf("%d %d\n",strlen(s),strlen(ar));
return 0;
}