When I “cout” an empty array, I get gibberish. Why?
int main() { char test[10]; cout << test; return 0; }
…returns some unicode blather. An easy answer I’m sure.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Since you didn’t initialize the array you got a garbage value (test[0] is what you are printing out).
Initialize it:
Just like to note:
Just because some compilers initialize stuff (like some compilers initialize ints, floats etc., at 0) it is not always the case, and you can get a garbage value otherwise.