Logic differences in C and Java

That is because a[index++] = index = index + 2; invokes Undefined Behavior in C. Have a look at this From the link: ..the second sentence says: if an object is written to within a full expression, any and all accesses to it within the same expression must be directly involved in the computation of … Read more

Need help understanding “getbits()” method in Chapter 2 of K&R C

Let’s use 16 bits for our example. In that case, ~0 is equal to 1111111111111111 When we left-shift this n bits (3 in your case), we get: 1111111111111000 because the 1s at the left are discarded and 0s are fed in at the right. Then re-complementing it gives: 0000000000000111 so it’s just a clever way … Read more

Why is 1===1===1 false?

Yes, you’re exactly right. Here you have two equality checks, which have the same operator precedence. First one evaluates first, then its result applies to the next equality check. 1===1===1is the same as (1===1)===1 which is true===1 which is false, because here you check by values AND their types. 1==1==1 will result in true, because … Read more