Home » C Programming » Strings

What will be the output of the program? #include int main() { int i; char a[] = "\0"; if(printf("%s", a)) printf("The string is empty\n"); else printf("The string is not empty\n"); return 0; }

Correct Answer: The string is not empty

Explanation:

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


Step 1: char a[] = "\0"; The variable a is declared as an array of characters and it initialized with "\0". 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 not empty".


← Previous Question Next Question→

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion