字符串常量与字符数组

字符数组的初始化:

char a[6] = "hello1";//
char b[6] = {'h','e','l','l','o','2',0};
char c[] = "hello3";//c字符:h,e,l,l,o,3,\0
char d[] ={'h','e','l','l','o','4','\0'};//d字符:h,e,l,l,o,4,\0
 strcpy(a,b); //以\0为结束字符,但a,b空间仅保存前6个字符,无保存最后\0字符。故会将b之后的字符拷贝到a字符数组中。将会修改到a字符数组空间之后信息,导致程序崩溃
printf("%s\n",a);




猜你喜欢

转载自blog.csdn.net/xmzzy2012/article/details/79854880
今日推荐