+ 4

If statement if(???){ Printf("hello");}else{printf("world");} wht is the condition and output is :hello world

condition???

26th Oct 2016, 8:59 AM
Renganathan S
Renganathan S - avatar
7 Réponses
+ 7
!(printf("hello ")) by putting this in condition we get the output as Hello world... bcz while condition is getting chckd it prints hello and as the condition is false so world will also get print hnce hello world is printed...
26th Oct 2016, 1:26 PM
Harimangal Pandey
Harimangal Pandey - avatar
+ 5
@Pandey: Not bad. I guess it's my fault for interpreting the question as "Run both the if and the else blocks in one go".
26th Oct 2016, 1:33 PM
Zen
Zen - avatar
+ 4
when if statement works else cannot be used so this is not possible
26th Oct 2016, 12:12 PM
Lara
Lara - avatar
+ 3
Lara is right, if your if is executed only once, you will either execute the if block or the else block, depending on whether the condition is true or not. If your if is executed several times however, it becomes possible. for (int i = 0; i < 2; i++) { if (i == 0) { printf("Hello "); } else { printf("world\n"); } }
26th Oct 2016, 12:57 PM
Zen
Zen - avatar
+ 2
I'm sure that 100% possible #Lara
26th Oct 2016, 12:14 PM
Renganathan S
Renganathan S - avatar
+ 2
#pandey I expect this answer only .......... thanks All the best!
26th Oct 2016, 1:27 PM
Renganathan S
Renganathan S - avatar
+ 1
#zen your answer also absolutely correct but without for loop only condition enough to display both blocks ...try this easy only
26th Oct 2016, 1:06 PM
Renganathan S
Renganathan S - avatar