✏️ 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
💡

Answer with Explanation

Corrected Code:


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