I need help with the following questions in
I felt the answer would be 21,13,13,13 but the answer is 22,13,13,13.How b is coming as 22?
I felt the answer should be 0, 1, 2, 3, 4, but is 0,0,1,2,3,4.How is the extra 0 coming?
4) why does 11 ^ 5 show 14
5)here a should have been 13(5*2+3) but it is coming as 25.How?
6)Why is this creating an infinite loop?
4.) ^ is the binary XOR operator. The calculation goes like this:
00001011 // 11
00000101 // 5
00001110 // 11 xor 5 = 14
5.) Assignment operators (including compound assignment, like *=) have lowest precedence. The calculation goes:
a *= 2+3;
a *= 5;
a = 5*5;
a = 25;
6.) You get an infinite loop because you're never incrementing the loop variable i. You're passing i to the increment function by value. The function increments a copy of i, and leaves the original variable like it was. A working increment function would look like this:You would call it like this:
The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.
posted 6 years ago
@Stephan van Hulst thanks for the explanations!.
I have got 1 more question.