188k views
5 votes
nt[] num = new int[100];for (int i = 0; i < 50; i++)num[i] = i;num[5] = 10;num[55] = 100;What is the value of num.length in the array above?1. 02. 1003. 994. 101

1 Answer

7 votes

Answer:

Option 2. 100 is correct.

Explanation:

In the above example, we have assigned the value 100 to the array num[] while creating the object of that array.

In the next line, we are assigning the values to the array num[] through the loop which will be executed till less than 50 values as it will be started from 0 but in the next line from that we are getting the total number of elements of that array which will be 100 because length function is used to get the total number of elements in the array which is already assigned as 100.

User BinCodinLong
by
8.0k points