M_Prince
M_Prince

Reputation: 11

Variable isn't being set properly

The problem is with this for loop:

for (int i = 0; i < n; i++);
{
    a = y & 1;
    y = y >> 1;
    b = a | b;
    b = b << 1;
}

you see i have set n to 4 so the compiler should've went four times through the loop, but it only goes through once (I added a "printf" to print 'i' and it prints 4). Why is i being set to 4 instead of zero?

ps I'm using visual studio 2013

Upvotes: 0

Views: 50

Answers (1)

john
john

Reputation: 87959

for (int i = 0; i < n; i++);
                           ^

Extra semi-colon. Easy mistake to make.

Upvotes: 3

Related Questions