What is legal declaration of array in the following and explain why?and also explain why not others? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
0

What is legal declaration of array in the following and explain why?and also explain why not others?

int a[][]=new int[4][4]; int[] a[]=new int[4][4]; int a[][]=new int[][4]; int[] a[]=new int[4][];

25th Dec 2017, 7:30 AM
Saikrishna Reddy
Saikrishna Reddy - avatar
1 Antwort
+ 7
An OCA question. All of them are legal except for the third one. int a[][] = new int[][4]; The dimensions must be created from left to right. The compiler cannot possibly allocate 4 slots of int to an arbitrary number of int[]. int[] a[] is simply equivalent to int[][] a and int a[][].
25th Dec 2017, 8:06 AM
Hatsy Rei
Hatsy Rei - avatar