sam <(EMail Removed)> wrote in news:1182868592.336797.296630
@x35g2000prf.googlegroups.com:
> HI,
> My friend just take a look at what i am saying
> s[worllen11]++;
> IN THIS VALUE OF ARRAY WILL BE 18
> IN next iteration again value of wordlen will be worldlen(because we
> are not changing the value of wordlen in iteration)
> means the value of wordlen will remain 20 in next iteration also and
> we are minusing 2 from this , then we get the same value inside array
> that is 18
> SEE HOW THIS POSSIBLE EVERY TIME IN NEXT ITERATION ALSO THE VALUE IN
> ARRAY REMAIN SAME AND SO AFTER INCREMENTING SUCH ARRAY ALSO THE VALUE
> CAN REMAIN SAME FOR THE NEXT ITERATION ALSO
> So
> This concept of mine(may be MISCONCEPT) BUT I want make clear what is
> boiling in mind
> Please Help me here?_?_?_
> I am really confused!!!!!!!!!
Unfortunately so are we. At least I'm not entirely sure what you are
attempting to do.
Let us assume an array of 3 items, and worllen is 3 (because I don't want
to write 20 array values every time....):
int worllen = 3;
int s[3];
s[0] = 0;
s[1] = 0;
s[2] = 0;
Also, let's use a loop of 10 iterations, performing your operation:
for (int i = 0; i < 10; ++i)
{
s[worllen  1  1]++;
}
Since worllen isn't modified during this loop, the loop effectively
behaves as if you had written:
for (int i = 0; i < 10; ++i)
{
s[3  1  1]++;
}
And if we calculate the constant expression in there, you end up with
effectively the following loop:
for (int i = 0; i < 10; ++i)
{
s[1]++;
}
The array starts with the values: { 0, 0, 0 }.
After the first iteration, the array will contain: { 0, 1, 0 }.
After the second iteration, the array will contain: { 0, 2, 0 }.
.....
After the tenth iteration, the array will contain: { 0, 10, 0 }.
