Printf MCQ 5 : Printf Without Using Semicolon
Printf Multiple Choice Questions : Printf Without Using Semicolon once
Que : How to Print Any Word in C Without Using Semicolon only once
Way 1 :
while(printf("Hello")) { }
Way 2 :
if(printf("Hello")) { }
Way 3 :
if(printf("")) { } else if(printf("Hello")) { } else { }
Way 4 :
#define PRINT printf("Hello") main() { if(PRINT) { } }
Which Way is Correct
Options :
- All the 4
- 1,2,3
- 1,2,4
- 2,3,4
[toggle title=”Output”]2,3,4[/toggle]
Switch to Printf MCQ Home : Click Here
How and Why ?
- First Way Prints “hello” Infinite Times.
- Click Here to See Printing Hello without using Semicolon
- printf statement Returns the Length of the String Specified in Double Quotes
- In Way 3 printf(“”) returns zero and if(0) is Considered as False Condition so Control Goes to else if Statement .
- Way2 & Way4 are Same , but in Way4 PRINT is Replaced by printf(“Hello”) by Preprocessor i.e before Compiling