Character Array MCQ 9 : Printing String inside If Statement




Character Array MCQ 9 : Printing String inside If Statement


What is the Output of the Following Program ?

#include<stdio.h>
#include<string.h>
void main()
{
char str[]="\0";
 if(printf("%s",str))
   printf("Non Empty String");
 else
   printf("Empty String");
}

Options :

  1. \0Non Empty String
  2. Non Empty String
  3. Empty String
  4. \0Empty String

Output:


Switch to String MCQ Home : Click Here


How and Why ?

  • ‘\0’ is Non Printable Character.
printf("%s",str)
  • Above Printf Prints “Nothing“.
  • So Printf Returns 0 [ As No Character is Printed On Screen ]
if(0)
  • Zero Inside If Statement Indicates “False Condition“.