A technical blog about programming and technology.

Tuesday, April 10, 2007

Answer!

Yesterday a few people were asking about possible solutions to the problem. Here is my solution.

	if(!printf("hello")) {
printf("hello");
}
else {
printf("world");
}
At a glance it seems impossible. There is no way to take both paths in an if statement.Therefore we need a 
function that returns false and prints hello.
If you know C/C++ really well you'd know that printf returns the number of
characters printed to stdout and if you negate that, you get zero. I welcome any other solutions that you come up with.
printf reference

2 comments:

Marcus said...

I might extend it a bit and look for if not true OR if not false.

Could be wrong, but hey.

Marcus said...

actually what am I saying...it would never reach the else statement.