I wrote the code below some months ago. Now I'm unable to understand it's working. At the bottom is given its output which also has my queries inline. Please help me with them. Thanks.
#include <iostream>
#include <cstdlib>
using namespace std;
const int C = 5;
char str[C];
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;
cout << static_cast<int>(' ') << endl;
system("pause");
return 0;
}
OUTPUT:
" " // [COLOR="#FF0000"]it shows as if each element of char str[C] contains empty space, shouldn't it be some random value[/COLOR] 00000 // [COLOR="#FF0000"]why all these 0s?[/COLOR] 32 // [COLOR="#FF0000"]what is this "32"?[/COLOR] Press any key to continue . . .


Sign In
Create Account


Back to top









