What’s the difference between the two code below.
int a[] = {0,0};
int a[2] = {0,0};
It seems I can assign value to a[3] in both cases. I can access a[3] in any case. So what’s the difference?
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.
There is no difference. In the first one, the compiler does the counting for you, which is nice if you decide to change the number of elements later on.
The fact that your compiler forgives you for assigning to or using
a[3]doesn’t mean that doing so is correct. In fact, you can’t even accessa[2]since it only has two elements, indexed by subscripts 0 and 1.