Campbell, what are we missing out here? It looks like a puzzle wherein you are asked to just get a different answer by just changing one line or operator etc? -- so as to get 22!
here, it is very simple -- it has 3 operands [0*10+10+010] in which the the result of multiplication yields 0 and the rest two gives you 10 and 8 (010 in octal yielding 8 in decimal). The sum is 18!
But, has Shirsa Ray Chaudhuri worked out why it is 18 or 22 and not 20?
There were three terms to the arithmetic:
0 * 10, which comes to 0.
10, which is one more than nine and one less than eleven.
and 010 which is one more than seven and one less than nine.
0 + 10 + 8 is 18.
Beginners are reminded that any integer literal beginning with 0 is in octal, so 010 is 10 in octal or 8 in decimal. Any integer literal beginning with 0x is in hexadecimal, so 0x10 is 16 in decimal.
When I had the 18 decimal, the %o tag made it print in octal, so I got the printout of 22.
Originally posted by shirsa ray chaudhuri: this all are wrong
No, the results people have posted, with or without cheating, are all correct. You can get 12 as an output too, by using the %x tag to print in hexadecimal. If the answers are to be picked from a multiple choice list of 28 30 34 36 and 101010, you must have made a mistake when you copied the original question.
Have you mistaken 0x10 for 0 multiplied by 10 (0*10)? If you were supposed to write 0x10, that would give one of the answers you listed. And as you have been asked, please post where you got the question from.
When I had the 18 decimal, the %o tag made it print in octal, so I got the printout of 22.
Campbell, not intended to beat around the bush! My intention and puzzling all was about the "%o" tag which you used by yourself! and that caused the confusion!
Originally posted by Campbell Ritchie: No, the results people have posted, with or without cheating, are all correct. You can get 12 as an output too, by using the %x tag to print in hexadecimal. If the answers are to be picked from a multiple choice list of 28 30 34 36 and 101010, you must have made a mistake when you copied the original question.
That's true. As Ulf suggested, you should have better Quoted your source, which would have avoided the confusions as Campbell pointed out -- misinterpreting the 0X as * (multiplication).
Campbell, that's perfectly agreed. If you see my very first post i told that it looked like a puzzle wherein you are expected to bring a change in the output by just altering a single value or operator etc., -- Here it was achieved by changing the output formatter!
That's okay but people should get clarified rather than getting confused -- Right? [ April 11, 2008: Message edited by: Raghavan Muthu ]