Mystery regarding for-loop.

Posted by primalpop on Stack Overflow See other posts from Stack Overflow or by primalpop
Published on 2011-02-01T07:01:57Z Indexed on 2011/02/01 7:25 UTC
Read the original article Hit count: 178

Filed under:
|

Hi,

I am stuck with this mystery regarding for loop.

    int abc[3], i, j;
    for(j=0; j<3; j++);
    printf("%d\n", j);
    abc[j] = abc[j] + 3;
    printf("%d \n", j);


Output: 

3
6 

Output should have been 3,3 as I've not changed value of j.

Adding 3 to the jth value of abc has resulted in change of value of j by 3. This happens only while exiting from a for loop and then trying to change the value of abc[j].

Maybe I am missing something pretty obvious. Any help would be much appreciated.

© Stack Overflow or respective owner

Related posts about c

    Related posts about for-loop