247,501 views
22 votes
22 votes
What is the error in the following pseudocode?

// This program uses an array to display five names.
Constant Integer SIZE = 5
Declare String names[SIZE] = "Meg", "Jack", "Steve", "Bill", "Lisa"
Declare Integer index
For index = 0 To SIZE
Display names[index]
End For

User Ryanoshea
by
2.4k points

2 Answers

20 votes
20 votes
I do not know the answers sorryy
User Loz
by
2.8k points
14 votes
14 votes

Final answer:

The error is that the For loop in the pseudocode iterates one too far, attempting to access an index out of the bounds of the array. The correct loop should iterate from 0 to SIZE - 1.

Step-by-step explanation:

The error in the provided pseudocode is in the loop's range. The For loop is iterating from 0 to SIZE, which includes the index that is equal to 'SIZE'. However, arrays in programming typically use zero-based indexing, which means they start at 0 and go up to but do not include the length of the array, in this case, 'SIZE'.

The loop should therefore iterate from 0 to SIZE - 1. When the index reaches 'SIZE', it will be out of bounds of the array, resulting in an error. The correct loop would be: 'For index = 0 To SIZE - 1'.

User Ayal
by
2.7k points