Sail E0 Webinar
Question


What will be the output of the program ?


#include<stdio.h>
int main()
{
int i;
char a[] = "\0";
if(printf("%s", a))
printf("The string is not empty\n");
else
printf("The string is empty\n");
return 0;
}
Options:
A .  The string is not empty
B .  The string is empty
C .  No output
D .  0
Answer: Option B

The function printf() returns the number of charecters printed on the console.

Step 1: char a[] = '�'; The variable a is declared as an array of characters and it initialized 

with "�". It denotes that the string is empty.

Step 2: if(printf("%s", a)) The printf() statement does not print anything, so it returns '0'(zero). 

Hence the if condition is failed.

In the else part it prints "The string is empty".



Was this answer helpful ?
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers