-
February 6th, 2014, 10:58 AM
#1
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 01:01 PM.
-
February 6th, 2014, 11:33 AM
#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!
Victor Nijegorodov
-
February 6th, 2014, 11:36 AM
#3
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, 11:44 AM
#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.
Victor Nijegorodov
-
February 6th, 2014, 12:08 PM
#5
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, 12:10 PM
#6
Re: Trace table for an array
Victor Nijegorodov
-
February 6th, 2014, 12:48 PM
#7
Re: Trace table for an array
Thanks again. Your assistance was greatly appreciated.
-
February 6th, 2014, 12:56 PM
#8
Re: Trace table for an array
Victor Nijegorodov
-
February 6th, 2014, 01:47 PM
#9
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|