# Trace table for an array

• February 6th, 2014, 09:58 AM
andraesatchell
Trace table for an array
So far I realize that when it enters the while loop, track will be 0, marr[track] will be marr[3]. is this correct or will 23+3 be the correct understanding. Does this mean it will be a infinite loop since track is never incremented. it will always be track<7

int marr[6]={23,67,12,9,33,7};
int track =0;
int ans = 2;

while(track<7)
{
marr[track] = marr[track] + 3;
if(marr[track]<20)
ans = marr[track] / ans;
}
• February 6th, 2014, 10:33 AM
VictorN
Re: Trace table for an array
Quote:

Originally Posted by andraesatchell
... then the If statement will be marr[6]<20? which is false because there is no index 6. Is this process the correct way?

Question
int marr[6]={23,67,12,9,33,7};

You declare the array marr[6];
which means that it contains six elements having indexes from 0 to 5. marr[6] is outside the allocated buffer!
• February 6th, 2014, 10:36 AM
andraesatchell
Re: Trace table for an array
Thank you for the clarification

marr[track] = marr[track] + 3; enters the while loop, track will be 0, marr[track] will be marr[3]

is this part correct. is it I should add 3 +23 or 0+3
• February 6th, 2014, 10:44 AM
VictorN
Re: Trace table for an array
Quote:

Originally Posted by andraesatchell
Code:

```int marr[6]={23,67,12,9,33,7}; int track =0; int ans = 2; while(track<7) {   marr[track] = marr[track] + 3;   if(marr[track]<20)       ans = marr[track] / ans; }```

Quote:

Originally Posted by andraesatchell
when it enters the while loop, track will be 0, marr[track] will be marr[3].

No.
when it enters the while loop, track will be 0, marr[0] will be 23 + 3 = 26.
• February 6th, 2014, 11:08 AM
andraesatchell
Re: Trace table for an array
understand. so track will always be 0 since there is no incrementation in the code, so it will always be adding 3 to marr [0]
• February 6th, 2014, 11:10 AM
VictorN
Re: Trace table for an array
Exactly!
• February 6th, 2014, 11:48 AM
andraesatchell
Re: Trace table for an array
Thanks again. Your assistance was greatly appreciated.
• February 6th, 2014, 11:56 AM
VictorN
Re: Trace table for an array
Quote:

Originally Posted by andraesatchell
Resolved

You must not remove nor edit your OP after you have resolved the problem! :mad::thumbd:
A lot of beginner could search for the problems similar to yours and after reading the thread very easy solve their ones. But now the whole thread you have started does not make any sense! :eek:
• February 6th, 2014, 12:47 PM
andraesatchell
Re: Trace table for an array
My apology for doing same. I have made the amendment. Thats a valid point you made.thanks again for everything