Originally Posted by
jackson6612
Anything which has been declared globally is initialized to zero, so every element of str[C] in your code is 0. Then, why doesn't cout'ing produces a series of 0's instead of spaces. Do you get me?
I'm going to assume an ASCII based character set and ask you to try this program:
Code:
#include <iostream>
using namespace std;
const int C = 5;
char str[C] = {74, 97, 99, 107, 0};
int main()
{
cout << '"';
for (int i = 0; i < C; ++i)
{
cout << str[i];
}
cout << '"' << endl;
for (int i = 0; i < C; ++i)
{
cout << static_cast<int>(str[i]) << ' ';
}
cout << endl;
return 0;
}
Why doesn't cout'ing produce "7497991070" instead of "Jack". Do you get me?