Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Interesting C Question (http://www.go4expert.com/forums/interesting-c-question-t6591/)

ndakota 28Sep2007 18:17

Interesting C Question

void main()
                          printf("Hello ");

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.

shabbir 28Sep2007 18:24

Re: Interesting C Question
printf("World"); would be nice option

ndakota 28Sep2007 18:28

Re: Interesting C Question

DaWei 28Sep2007 19:49

Re: Interesting C Question
A single if-else with a condition cannot take both branches. It's not an interesting question, it's a silly question.

An007kit 1Oct2007 17:26

The answer is....
condition --->if(!printf("hello"))

An007kit 1Oct2007 20:57

Re: Interesting C Question
Well dawei......that is not a silly question......actually that's a tricky question...... ;)

DaWei 1Oct2007 21:54

Re: Interesting C Question
Nothing tricky about it. It's silly. Your amazing solution only has one printf statement so it can't possibly

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 1Oct2007 22:01

Re: Interesting C Question
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..... :)

All times are GMT +5.5. The time now is 22:16.