+ 1

What is array??

while array needs both row and column, example of a one dimensional array. datatype arr[4]; if 4 is number of rows or column then where is rows or column?? since we have read that in an array arr[3][4], 3 is number of rows and 4 is column. i even didn't get the arrayyyyyyyyy..

26th Jan 2018, 1:11 PM
Mubarak Hussain
Mubarak Hussain - avatar
2 Answers
+ 20
array is set of elements of same type //arr [3][4] means element in 2nd row & 3rd column https://www.sololearn.com/learn/Java/2149/?ref=app
26th Jan 2018, 1:27 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 1
RAM is one-dimensional. As such visualizing an array as a table is fundamentally flawed. An array is just an arbitrary number of elements, occupying a chunk of RAM, with a pointer to the first element. In case you don't know a pointer is a number that represents the physical address of a variable. So you have a pointer to the beginning of the array and arr[2] is just syntactical sugar for *(arr+2), or "get me the value stored at the address arr+2". (this is also why arrays start indexing at 0). Two-dimensional arrays are a little more complicated. You have a pointer to a list of pointers, and each of those pointers points to a list of elements. So arr[2][3] means "get me the value that is stored in memory 3*n bytes (where n is the size of the data type) after arr[2]". TL;DR: while arr[row][column] makes more sense, it doesn't matter as long as you're consistent and understand what is *actually* going on under the hood.
26th Jan 2018, 1:37 PM
Vlad Serbu
Vlad Serbu - avatar