KnowledgeBoat Logo
|

Computer Applications

How does the amount of storage (in bytes) depend upon type and size of an array? Explain with the help of an example.

Java Arrays

1 Like

Answer

The amount of storage depends upon the type and size of an array as every data type requires different storage space in memory and the number of elements (size) of an array determines how many memory blocks of same size are required.

To calculate the amount of storage required by an array we use the formula:
Size = size of data type x number of elements in an array

For example, int arr[] = new int[10]; will require 4 x 10 = 40 bytes space in memory.

Answered By

1 Like


Related Questions