When I declare a two-dimensional array like this:
char myArray[20][30] = {"ABC", "Is Easy As One Two Three"};
Can I assume that all other chars in this array are now set to \000?
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.
Objects are never partially initialised in C – if you have used an initialiser, then the entire object is guaranteed to be initialised (in this case, the “object” is the whole array of 20 arrays of 30 chars each). Any members not explicitly initialised are recursively initialised to zero (for arithmetic types), or NULL (for pointer types).
So the answer, in this case, is yes – all the
chars not explicitly given values by the initialiser are guaranteed to be 0.This is described in the C99 standard in section 6.7.8, Initialisation. The relevant paragraphs are:
and