0
I didn't understand pff plz someone explain to me how this arrays work
4 Answers
+ 1
Array is collection of data of same type. That is placed under one common name. Accessed with indexing beginning from 0.
Array is used so that related data can be stored at contiguous memory locations, unlike normal variable, which are stored any where they find place for their size.
But for example u created an array of 10 integers which will take 40 bytes (10 elements * 4 bytes each element) will be stored in memory wherever it finds the empty 40 bytes for it.
Array is created as:
datatype[] name= new datatype[size] ;
+ 1
The first bracket is the array "number" if you will. The next bracket is the index.
0
public class Program {
public static void main(String[] args) {
int[ ][ ] sample = { {1, 2, 3}, {4, 5, 6} };
int x = sample[1][0];
System.out.println(x);
}
} can you explain to me why outputs it's 4
0
thnk you sooo much guys