数组初始化
int main()
{ //像变量赋值一样,为数组的元素一次赋值
int socres[5] = { 99,89,78,67,78 };
for (int i = 0; i < 5; i++)
{
printf("%d\n", socres[i]);
}
}
int main()
//赋值时为数组前面元素赋值,如果数组长度超过赋值元素个数,后面元素依次默认赋值为0
{ int socres[5] = { 99,89 };
printf("数组长度:%d\n", sizeof(socres) / sizeof(socres[0]));
for (int i = 0; i < sizeof(socres) / sizeof(socres[0]; i++)
{
printf("%d\n", socres[i]);
}
}
int main()
{ int socres[] = { 99,89,78 };
printf("数组长度:%d\n", sizeof(socres) / sizeof(socres[0]));
for (int i = 0; i < sizeof(socres) / sizeof(socres[0]); i++)
{
printf("%d\n", socres[i]);
}
}
int main()
//给数组赋值全为0
{ int socres[3] = { 0 };
printf("数组长度:%d\n", sizeof(socres) / sizeof(socres[0]));
for (int i = 0; i < sizeof(socres) / sizeof(socres[0]); i++)
{
printf("%d\n", socres[i]);
}
}
END