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!
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
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.
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]
Re: Trace table for an array
Re: Trace table for an array
Thanks again. Your assistance was greatly appreciated.
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:
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