0

What would be the values of theData starting from index 0, if theData: 3 5 5 2 7 (Assume the data type is Integer) item: 5 f

WHAT IS THE OUTPUT

15th Mar 2025, 6:18 PM
Sara Hassn
Sara Hassn - avatar
2 Answers
0
not only in java, indexing starts from 0, that means: the first item/number
15th Mar 2025, 8:30 PM
Mihaly Nyilas
Mihaly Nyilas - avatar
0
Sara Hassn Just about every language uses index 0 for the first element in arrays/lists. This is due to how computers allocate memory for arrays/lists. A continuous block of memory is assigned to the list variable based on number of elements in list and memory size of the stored data type. The list variable effectively points to the start of this memory block. To quickly access any element in the list, the computer takes provided index, multiplies by size of data type, and adds that to starting point of the list to get the necessary memory address. Since the list variable is already pointing at start of memory block (i.e. first element), you don't need to add anything to it to get first element. EXAMPLE - if each integer took 4 bits myNums[0] - address of myNums + (0 * 4bits) = myNums address = starting address of 1st list element myNums[1] - address of myNums + (1 * 4bits) = myNums address + 4bits = starting address of 2nd list element
16th Mar 2025, 12:24 AM
Shardis Wolfe