How many of you enjoy solving puzzles of c/ c++ language....
27 Dec 06
this puzzle is based on ASSOCIATIVITY of ++/-- operators i can solve it ... let me try ... the output will be .. 10 11 11 11 AM I RIGHT .... i liked this discussion, i will add more puzzle here , and i will love to see more puzzles from you too
13 Jan 07
the result of this depends and vary compiler to compiler. actually x++ and ++x are treated diffrently inside. x++ require a temporary variable which can change the actuall result. furthermore, comiler must resolve the value of x before calling printf routine.
28 Jan 07
But as you said associativity will not be concerned with all compilers. If we take that this is how output will be. 1. Associativity from right. preincrement x=11 hence prints 11. 2. post increment. print 11 again x increments to x=12. 3. Double pre increment printing values as 11 and 10 so output: 11121110
14 Jan 07
if i am right your real name is zubair... am i right? the correct output is selected as best response, actually it(++/--) has associativity from right to left so first of all the right most operator is handled then last but one and so on ... hope you have got it .....
20 Jan 07
the associativity of ++ and -- is right to left , that means they starts there evaluation from right to left , then comes the point called pre increment/ecrement, and post increment/decrement in pre incre/decre the value of variable is incresed/decreased first then the work is performed but in post incre/decre first of all the work is performed then the variable is increased or decreased , now check it you will get it with this knowledge...
24 Jan 07
if you know java , ou can answer c questions too, their behavior is same , only difference is ... java is pure oops , c is not , c++ is oops but not strictly enough like java, but variable creation, condition checking, looping,array, functions all these are same in these languages, so keep posting on puzzles sections of my discussions
17 Feb 07
yes but there printf line is complicated for me, but i will try my best, i am student yet so i have to strong my coding base, i will also start my java puzzle discussion, then we will challenge each other ok dholey uncle please teach me c/c++ and help me i want to strong my base in loopings, my looping is too weak.
12 Feb 07
I see all the wrong answers here are explained and given in steps but right ones are just put here. If it starts from right, then there must be following steps: OutPut 1. ++x = 11 (as x is incremented first) 2. x++ = 11 (x is now 12) 3. --x = 11 (as x is decremented first) 4. --x = 10 (as above) Why not?
12 Feb 07
Oh sorry, I had written that to complain, but now I see I have got the point. My answer too is 10111111. But you should explain stepwise! In my case I must add that though we start from right, output will be from left i.e. steps 4-3-2-1 Thanks for the puzzle. I was really missing my c++ :)
15 Feb 07
its really a nice discussion.this problem basically test your knowledge about postfix and prefix oprators.in my opinion the output is 10 9 11 11.maybe i am wrong.this type of puzzeles are common in placement papers.nice to solve it in mylot and earn few cents by doing so.