Interesting C Question

ndakota's Avatar, Join Date: Aug 2007
Go4Expert Member
Code:
void main()
{
		 if(CONDITION)
			   printf("Hello ");
		 else
			   printf("World");
}
Replace CONDITION with such a condition that both the printf statements get executed.
You can't have a loop or other things in main()
According to my knowledge it's not possible.
But if it is possible, please let me know.
Thanks
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
printf("World"); would be nice option
ndakota's Avatar, Join Date: Aug 2007
Go4Expert Member
thaks
DaWei's Avatar, Join Date: Dec 2006
Team Leader
A single if-else with a condition cannot take both branches. It's not an interesting question, it's a silly question.
An007kit's Avatar, Join Date: Oct 2007
Go4Expert Member
condition --->if(!printf("hello"))
An007kit's Avatar, Join Date: Oct 2007
Go4Expert Member
Well dawei......that is not a silly question......actually that's a tricky question......
DaWei's Avatar, Join Date: Dec 2006
Team Leader
Nothing tricky about it. It's silly. Your amazing solution only has one printf statement so it can't possibly
Quote:
Originally Posted by original poster
such a condition that both the printf statements get executed.
That isn't a trick; that's being unable to read and comprehend.
An007kit's Avatar, Join Date: Oct 2007
Go4Expert Member
DaWei....there are still two printf statements that get get executed.....one that prints hello and other that prints world.......so i think there is no problem in reading neither in comprehension.....