If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.
You know, I've been thinking about the third answer and it is actually very spectacular. I mean, think about it for a second. You have to take a condition that almost never uses the "+" sign to reach that condition.
Rob, how did you figure it out? I'm going to be impressed about this all day
Ladies and gentlemen, take my advice, pull down your pants and slide on the ice.
In C it is quite common to see a construct such as:
if (a) { blah blah }
as a shorthand for:
if (a!=0) { blah blah }
Basically all expressions in C return a value, and if the return value is treated as either true or false (as in this case), then you have something to work with.
My buddy at work wants to knwo if anyone else knows of any other code teasers? Alo, anybody know the link to some of the old brain teasers posted throughout the years?
Dave
Ladies and gentlemen, take my advice, pull down your pants and slide on the ice.
Sorry Ribbit, Chuck's right. That wouldn't execute ever.
- Gurm
The Internet - where men are men, women are men, and teenage girls are FBI agents!
I'm the least you could do
If only life were as easy as you
I'm the least you could do, oh yeah
If only life were as easy as you
I would still get screwed
int i, n = 20;
for (i = 0; i < n; n--)
printf("-");
how about the above? my C is rusty but just changing n for i for the decrement should work.. no compiler with me so u have to check for me..
Edit: home at last to explain the logic
after you decrease n 20 times, u will have printed "-" 20 times and by now n=0 as the printf statement is executed before the n-- ,
and since i=0, i < n would cause the loop to end as zero is not equal to zero, this is a kind of reverse logic
Last edited by Belwarrior; 17 October 2003, 05:09.
Life is a bed of roses. Everyone else sees the roses, you are the one being gored by the thorns.
AMD PhenomII555@B55(Quadcore-3.2GHz) Gigabyte GA-890FXA-UD5 Kingston 1x2GB Generic 8400GS512MB WD1.5TB LGMulti-Drive Dell2407WFP
***Matrox G400DH 32MB still chugging along happily in my other pc***
Comment