Trace Table for an Arrary

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

marr[track] = marr[track] + 3;
ans = marr[track] / ans;
Last edited on
So far I realize that when it enters the while loop, track will be 0, marr[track] will be marr[3]


that line will set the first element in your array from 23 to 26.

you never change the value of track so you'll have an infinite loop, or possibly a div by zero exception due your last line in main()
Last edited on
i didn't even realize that. for some reason I thought track would be 3 (3+0).Thank you for the clarification.

so when I reach the If statement, will it be If 26<20? which would be false, therefore ans=0/2.Is this a correct explanation mutexe

not really no.
will it be:

will that be

therefore ans=0/2


Because the condition fails, it won't run into your if condition, and ans does NOT get re-assigned and therefore ans will remain 2 (which is what you initialized it with).

also: each iteration of your loop will add 3 to the first element of the array, so it'll go:
29, 32, 35, 38

*but* you'll hit the maximum value for an integer, get wrap around, and then get a division by zero exception.

You should step through this in a debugger rather than theorizing about the process.

Last edited on
Thank you very much for this beautiful explanation. I really appreciate it
Thank you very much for this beautiful explanation. I really appreciate it

If you really appreciate it, you won't modify your posts so that others happening upon this thread won't have the context to decipher what went on here. Your last post in combination with the OP edit is essentially saying "In thanks for your help, I'm making this thread useless for anyone else."
So true. I must apologize cire.
Topic archived. No new replies allowed.