Did you try the code? char values are implicitly null characters '\0' in the code I posted.
If what you're saying is true, then int a[4] = {4} would make the array be {4, 4, 4, 4}. It's not, it's {4, 0, 0 ,0}.
Doing
1 2 3 4 5 6 7 8
|
int main()
{
int a[100];
for (int i = 0; i < 100; i++)
{
std::cout << a[i] << ' ';
}
}
|
will make everything uninitialized.
Doing
1 2 3 4 5 6 7 8
|
int main()
{
int a[100] = {4};
for (int i = 0; i < 100; i++)
{
std::cout << a[i] << ' ';
}
}
|
Initializes first element to 4, and rest to 0.
Like wise
doing
1 2 3 4 5 6 7 8
|
int main()
{
char c[100];
for (int i = 0; i < 100; i++)
{
std::cout << c[i] << ' ';
}
}
|
Will make c have junk values.
Doing
1 2 3 4 5 6 7 8
|
int main()
{
char c[100] = {'A'};
for (int i = 0; i < 100; i++)
{
std::cout << c[i] << ' ';
}
}
|
will make the array be {'A', '\0', '\0', '\0',...}
Anyway, imo it's bad to rely on implicit things like that, I would go through a loop either way to initialize the values. Also to answer the original point, no, there is no way to make your char array have '0' for all indexes (the character zero, not the null character '\0') without a loop.