In: Computer Science
Question 1: As you know that “the base address or the starting address of any array is its name”. Keeping this information, answer
a. Why the first index of any array always starts from zero. Although it points to the first location of an array.
b. The reason why the last index is always one less than array length is “the first index starts from zero”. Does it seems to be a correct reason justify.
c. What is the offset address of any array NAMED AS ARR1 who starting address is A011234h.
d Can you find the offset address of the 6th element of array given in 3? If its data type is INT.
e. What is the offset address of last element of an array stated in 3? If the length of array is 5 and data type is char.
Kindly solve the complete Questions with all parts......
Array is a container object that holds a fixed number of values of a single type. The length of an array is established when the array is created.
Answering a:
As you have said, "the base address or the starting address of any array is its name”. You are right here.
Actually, Array name is a constant pointer, pointing to the base address. When you use arr[i] the compiler manipulates it as *(arr+i). Since int range is -128 to 127,the compiler thinks that -128 to -1 are negative numbers and 0 to 128 are positive numbers.So array index always starts with zero.
Answering b:
As the indexing starts from zero, the last index will be always less than length of the array. For example, when you count number of week days starting from zero with Sunday, you will be ending with 6 for Sunday.
Answering c:
Offset for a memory operand is called, the operand's effective address or EA. It is an unassigned 16 bit number, that expresses the operand's distance in bytes from the beginning of the segment in which it resides.
We know that the base address is A011234h.
So we know that the first element, (offset 0) is at location A011234h. Since arrays must be stored on contiguous bytes, we know that the next element is stored at A011234h+2 ( A011234h + 2 bytes).