Trace table for an array
 CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com

# Thread: Trace table for an array

1. Junior Member
Join Date
Feb 2014
Posts
6

## 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;
}
Last edited by andraesatchell; February 6th, 2014 at 12:01 PM.

2. ## Re: Trace table for an array

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!

3. Junior Member
Join Date
Feb 2014
Posts
6

## 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

4. ## Re: Trace table for an array

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;
}```
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.

5. Junior Member
Join Date
Feb 2014
Posts
6

## 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]

6. ## Re: Trace table for an array

Exactly!

7. Junior Member
Join Date
Feb 2014
Posts
6

## Re: Trace table for an array

Thanks again. Your assistance was greatly appreciated.

8. ## Re: Trace table for an array

Originally Posted by andraesatchell
Resolved
You must not remove nor edit your OP after you have resolved the problem!
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!

9. Junior Member
Join Date
Feb 2014
Posts
6

## 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

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)