Given the following code fragment:int A[];int i = 0;A = new int A[4];while (i < 4){A[i] = 10;i = i + 1;}

  1. 0

  2. 3

  3. 10

  4. UNKNOWN


Correct Option: C

AI Explanation

To answer this question, we need to understand the given code fragment and how it initializes and assigns values to an array.

The code fragment initializes an integer array A and sets the length of the array to 4 using A = new int[4];. Then, it enters a while loop that iterates as long as the variable i is less than 4.

Inside the while loop, the code assigns the value 10 to the elements of the array A at index i using A[i] = 10;. After that, it increments the variable i by 1 using i = i + 1;.

Let's go through each option to understand why it is correct or incorrect:

Option A) 0 - This option is incorrect because the code assigns the value 10 to the elements of the array A, not 0.

Option B) 3 - This option is incorrect because the variable i is incremented by 1 until it is no longer less than 4. Therefore, the value of i will be 4 after the while loop ends.

Option C) 10 - This option is correct because the code assigns the value 10 to each element of the array A using A[i] = 10;. Therefore, after the code execution, all elements of the array A will have the value 10.

Option D) UNKNOWN - This option is incorrect because the code fragment clearly assigns the value 10 to the elements of the array A. The value is not unknown.

The correct answer is Option C) 10. This option is correct because the code assigns the value 10 to each element of the array A using A[i] = 10;.

Find more quizzes: