Q. | Refer to the following code segment. You may asume that arr is an array of integers. int sum = arr [0], i = 0;
while (i < arr. length)
{
i++;
sum+= arr [i];
}
Which of the following will be the resul of executing the segment?
|
|||||||
|
Answer: | Option D | |
Explaination: |
The intent is to sum elements arr (0), arr (1),...,arr (arr.legth-1). Notice, however, that when i has the value arr.leght-1 it is incremented to arr. leght in the loop. |
Discussion
Your Comments Goes here... |
Name | Discussion |
---|