Home / Questions / Find the errors in the given program segment and re-write the statements correctly to assign values to an integer array. int a = new int (5); for (int i=0; i
Explanatory Question

Find the errors in the given program segment and re-write the statements correctly to assign values to an integer array.

int a = new int (5);
for (int i=0; i<=5; i++) a[i]=i;

👁 120 Views
📘 Detailed Answer
🕒 Easy to Read
Read the answer carefully and go through the related questions on the right side to improve your understanding of this topic.

Answer with Explanation

Corrected Code:


int a[] = new int[5];
for (int i = 0; i < 5; i++)
    a[i] = i;