aliensbrain
  • Home
  • Study
  • Quizzes
  • 🎤AI Practicefree
  • Notebooks
  • Community
  • Sign in
  • Java Programming Fundamentals
  • Given the following code fragment: int A[]; int i = 0; A ...
Multiple choice technology programming languages

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

  1. 0

  2. 3

  3. 10

  4. Compile Error

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

The while loop runs 4 times (i = 0, 1, 2, 3), assigning 10 to each array index. A[3] is the fourth element and receives the value 10.

Keep practicing — related questions

  • Given the following code fragment: int A[]; int i = 0; A = new int A[4]; while (i < 4) { A[i] = 10; i = i +...
  • Given the following code fragment:int A[];int i = 0;A = new int A[4];while (i < 4){A[i] = 10;i = i + 1;}
  • Consider the code below: arr[0] = new int[4]; arr[1] = new int[3]; arr[2] = new int[2]; arr[3] = new int[1]...
  • int i,j; int ctr = 0; int myArray[2][3]; for (i=0; i<3; i++) for (j=0; j<2; j++) { myArray[j][i] = ctr; ++c...
  • Given the following code snippet; int salaries[]; int index = 0; salaries = new int salaries[4]; while (ind...
  • What will be the output of the following code segment? #include #include void main() { int a[]={0,1,2,3,4,5...
  • Consider the following line of code: int x[] == new int[25]; After execution, which statement or statements...
  • void main() { int a[2][3]={{1,2,3},{4,5,6}}; printf("%d\n",++**(a+1)); }
Play the full quiz 🎤 Practise this topic out loud
Advertisement
© Aliensbrain | all rights reserved
  • About
  • Contact
  • Terms and Condition
  • Privacy Policy