Consider an array of float. Calculate the difference between the address of…
2023
Consider an array of float. Calculate the difference between the address of the 1st and 4th element, assuming float occupies 4 bytes of memory.
- A.
16
- B.
4
- C.
12
- D.
8
Attempted by 664 students.
Show answer & explanation
Correct answer: C
To calculate the difference between the addresses of the 1st and 4th elements in an array of floats, where each float occupies 4 bytes:
Step 1: The 1st element starts at a given address, say A.
Step 2: The 4th element is 3 positions after the 1st element (since indexing starts at 1).
Step 3: Each element occupies 4 bytes, so the address difference is (4 - 1) × 4 = 12 bytes.
Thus, the difference between the address of the 1st and 4th element is 12.