KnowledgeBoat Logo
|

Computer Applications

Arrange the following in the descending order of number of bytes occupied.

(i) char x[20]
(ii) int a[4][2]
(iii) double b[6]

  1. (iii), (ii), (i)
  2. (iii), (i), (ii)
  3. (ii), (iii), (i)
  4. (i), (ii), (iii)

Java Arrays

3 Likes

Answer

(iii), (i), (ii)

Reason — To find the number of bytes occupied by each array, we multiply the number of elements by the size of each data type:

(i) char x[20] — 20 elements * 2 bytes = 40 bytes
(ii) int a[4][2] — 4 * 2 = 8 elements * 4 bytes = 32 bytes
(iii) double b[6] — 6 elements * 8 bytes = 48 bytes

Now arranging in descending order: (iii) 48 bytes, (i) 40 bytes, (ii) 32 bytes

Answered By

1 Like


Related Questions