在 C++ 中,如果我们声明一个包含四个元素的数组,这些元素可以存储值吗?我的意思是,如果我们声明以下数组:
#include <iostream>
int main()
{
int a[4];
double res;
double avg;
avg = res = 0.0;
for(int i=0; i<4; i++)
{
cout<<"Please enter age ";
cin>> a[i];
}
for(int i=0; i<4; i++)
{
cout<< "You have entered these ages " <<a[i];
cout<<endl;
res += a[i];
}
avg = res/4;
cout<< "Total is "<<res <<endl;
cout<< "Avg is "<<avg;
}
上面的这个程序是一个带有整数(数字)数组的程序,而在字符数组中我们可以为字符数组的元素赋值吗?