Why
int arr[][]=new int[5][];
declaration is perfectly fine but
int arr[][]=new int[][5]
generates compile time error ?
Please do help me. I am not able to understand why is that so?
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.
int arr[][](which is more typically written asint[][] arr) is an array, each element of which is in turn a reference to an array.new int[][5]would mean “create an array of unknown length, each element of which is a reference to an array, each of length 5”. Obviously, that doesn’t make sense.On the other hand,
new int[5][]means “create a length-5 array, each element of which is a null reference to an array”.