char
str1[
32
];
char str2[ 32 ] = {0} ;
char str2[ 32 ] = {1} ;
char str2[ 32 ] = {0} ;
char str2[ 32 ] = {1} ;
在上述三种数组初始化方式中:
数组str1中的32个元素的值为未指定的随机值;
数组str2中,32个元素的值均为0 ;
数组str3中,str3[0]的值为1,其余31个元素的值为0;
以下是引用NetMD网友的解释:
“按照标准,聚合类型(数组、结构等)的初始化被定义如下:
被指定初始化值的部分由初始化值初始化;
未被指定初始化值的部分由T()方式初始化;
”
下面是测试程序和结果
#
include <stdio.h>
# include <stdlib.h>
# include <string.h>
int main (a , b)
{
char str1[ 32 ] = { 1 };
char str2[ 32 ] = { 0 };
int i;
for (i = 0 ; i < 32 ;i ++ )
printf ( " %d__ " , str1[i]);
printf ( " " );
for (i = 0 ; i < 32 ;i ++ )
printf ( " %d__ " , str2[i]);
printf ( " " );
}
# include <stdlib.h>
# include <string.h>
int main (a , b)
{
char str1[ 32 ] = { 1 };
char str2[ 32 ] = { 0 };
int i;
for (i = 0 ; i < 32 ;i ++ )
printf ( " %d__ " , str1[i]);
printf ( " " );
for (i = 0 ; i < 32 ;i ++ )
printf ( " %d__ " , str2[i]);
printf ( " " );
}
jekyll@ubuntu:
~/
prgramming$ .
/
a.
out
1__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__
0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__
1__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__
0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__0__