let the array be "int a[10][10][10];"
the address of this multidimensional array can be extracted by the following codes in printf statement.
1. printf("%p", &a[0][0][0]);
2. printf("%p",a);
"a" gives the base-address of array
C-style example: sometype array [P][Q][R]; addr (array,I,J,K) = (char *)array + sizeof (sometype)*(I*Q*R + J*R + K)
Computer memory is linear so a one dimensional array can be mapped on to the memory cells in rather straight forward manner.To find the actual address of an element one needs to subtract one from the position of the desired entry and then add the result to the address of the the first cell in the sequence.Having said that therefore it is necessary to know the starting address of the space allocated to the array and the size of the each element, which is same for all the elements of an array.The the location of the Ith element would be B+I*S where B is the base address(Starting address of the array) and S is the size of each element of the array.
Basically, &array[i]; That is, the memory location for an array object with index i. Or, you can do: (array + i);
by using index position we can find the particular element in array.
== Java does not allow reference to memory locations. == In C: for (i=0; i<n; ++i) printf ("a[%d] is at %p\n", i, &a[i]);
To find the size of an array in PHP you can either use the count() function or the sizeof() function as they will produce the same result. <?php $array = array(1, 2, 3, 4, 5, 6, 7); echo count($array); // outputs 7 echo sizeof($array); // outputs 7 ?>
Divide the array in half and get the median of each half
array.length will return the number of elements in array.
(array.length - 1) will find the index of the last element in an array (or -1 if the array is empty).
To find the median of an array of numbers, first, arrange the numbers in ascending order. If the array has an odd number of elements, the median is the middle number. If the array has an even number of elements, the median is the average of the two middle numbers.
int findMax(int *array) { int max = array[0]; for(int i = 1; i < array.length(); i++) { if(array[i] > max) max = array[i] } return max; }
sizeof(some_array)