Question: Debugging: When I ran this program it printed 19. #include void main(){ int i, a[5]={1,2,3,4,5},sum; sum = 0; for(i=1; i

Debugging:

When I ran this program it printed 19.

#include

void main(){

int i, a[5]={1,2,3,4,5},sum;

sum = 0;

for(i=1; i<=5; i++)

sum+= a[i]

cout<

}

This program compiled and ran but printed 19. grrrr.

a. The programmer expected the program to print 15. Why?

ANS:

b. But there is a bug in the code that would have precluded this. What is the bug?

ANS:

c. What must be going on to cause this output, i.e. what value must be where in memory (for whatever reason, thats not your problem now) to cause the program to print 19?

ans:

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!