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 :

  1. All the 4
  2. 1,2,3
  3. 1,2,4
  4. 2,3,4

[toggle title=”Output”]2,3,4[/toggle]


Switch to Printf MCQ Home :  Click Here


How and Why ?

  1. First Way Prints “hello” Infinite Times.
  2. Click Here to See Printing Hello without using Semicolon
  3. printf statement Returns the Length of the String Specified in Double Quotes
  4. In Way 3  printf(“”) returns zero and if(0) is Considered as False Condition so Control Goes to else if Statement .
  5. Way2 & Way4 are Same , but in Way4 PRINT is Replaced by printf(“Hello”) by Preprocessor i.e before Compiling