Each Friday we run Quiz on Twitter and give away one of our boards. This runs for more than year now and it very popular. Usually the questions I ask there are related to Hardware to make balance with the Weekend Programming Challenge. Last Friday the question was: **“define X in such way that (X+1 == X) is true”** my idea was that if X is big enough due to the computer arithmetic precision the statement above will be evaluated as true. so my answer was: **#define X 1.0/0.0** The Quiz runs for one hour and for my big surprise this became real brainstorm and I got many correct answers which were not like mine: **#define X FLT_MAX** **float x = 1e20** **double X = INFINITY;** **int a() {static int x=0; return x++;}** **#define X a()** **#define X 1|1** **#define X 1||1** **#define X std::numeric_limits<double>::infinity()** **var X= 1.7976931348623157E+10308** **#define x=log(0)** **#define X 2 && 1** **#define X 1,1** well done! … although I still try to figure out why #define X 1,1 works 🙂

## When (X+1==X) is true or how Friday Free Board Quiz became Brainstorm

26 Aug 2013 2 Comments

in friday quiz, programming Tags: board, brainstorm, free, friday, quiz

kasimir

Aug 26, 2013@ 12:15:52Never new this could be used outside for-loop headers… obviously it can 🙂

http://en.wikipedia.org/wiki/Comma_operator

Frank L.A.

Aug 26, 2013@ 14:35:29AFAIR, the comma operator evaluates both sides (expressions) and returns the right hand side value as result. Therefore, with #define X 1,1 for instance if(X+1==X) expands into if(1,1+1==1,1), which evaluates to if(1,2==1,1) and further if(1,0,1), returning the rightmost 1 as end result, which is interpreted as the boolean true.