December 23rd, 2012, 12:03 AM
Please explain output of this code
#define PRINT(int) printf("%d\n",int)
x=x&&y || z;
PRINT(x || !y&&z);
z=x ++ -1;
z+= -x ++ + ++ y;
December 23rd, 2012, 03:50 AM
Not another one!?
The point of the code is to demonstrate the folly of writing such code. No other explanation is required - just don't write ridiculous code (if it was ever necessary to state that).
Academics who think setting this sort of exercise is useful need a reality check. Few developers would have ever thought to write such code unless the idea were planted by such an exercise.
Always remember what Brian Kernhigan says:
Last edited by clifford; December 23rd, 2012 at 03:56 AM.
December 23rd, 2012, 09:38 AM
This was a puzzle that i didnt understand .... not my own ... if u feel comfortable you can explain even if its ridiculous...afterall aptitude has such ridiculous questions...
Originally Posted by clifford
December 23rd, 2012, 03:09 PM
It's your exam / homework / assignment, you figure it out.
Well at least as much as you're able.
Post your thoughts here and we'll tell you if you're on the right track or whether you need to re-think your approach.
You're not going to get away with a "gimme the answers" post around here. Start pulling your own weight a bit.
Start with the first one - it's pretty easy.
December 24th, 2012, 09:16 AM
It is all very simple and well defined except:
If you cannot fathom all except perhaps that part, then you are truly lost.
Things you need:
- In a boolean expression any non-zero operand is regarded as TRUE, zero is FALSE.
- The value of a boolean expression resolving to TRUE when cast to an integer is 1.
- TRUE OR <any-value> = TRUE
- <any-value> OR TRUE = TRUE
- The order of evaluation in the absence of parenthesis is determined by the operator order of precedence
- The requirements of pre/post decrement/increment operators conflict with order of precedence in ways that are arcane, confusing, and not always well-defined - avoid.