Question:

If array is declared as given below Java statement, how many bytes require to store it in memory?
int marks[][] = new int[5][3];

Show Hint

Memory required for arrays can be calculated as:
{Number of elements × Size of data type}.
  • 15
  • 60
  • 5
  • 3
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is B

Solution and Explanation

Step 1: Understanding the array declaration.
The statement given in the question is:
int marks[][] = new int[5][3];
This means that the array has:
5 rows
3 columns
So the total number of elements in the array will be:
5 × 3 = 15 elements
Step 2: Memory required for each element.
In Java, the data type int occupies 4 bytes of memory.
Therefore each element of the array requires 4 bytes.
Step 3: Total memory required.
Total elements = 15
Memory per element = 4 bytes
Total memory required =
15 × 4 = 60 bytes
Step 4: Evaluation of options.
(A) 15: Incorrect. This represents the number of elements, not memory size.
(B) 60: Correct. This is the total memory required in bytes.
(C) 5: Incorrect. This is the number of rows only.
(D) 3: Incorrect. This is the number of columns only.
Step 5: Conclusion.
Thus, the total memory required to store the array marks[5][3] is 60 bytes.
Final Answer: 60
Was this answer helpful?
0
0