1 1 vote 1. #include <stdio.h> int main() { int i; char a[] = ""; // no tab space in between if(printf("%s",a)) printf("string empty"); else printf("string is not empty"); return 0; } Output: string is not empty 2. #include <stdio.h> int main() { int i; char a[] = " "; // used a tab space in between if(printf("%s",a)) printf("string empty"); else printf("string is not empty"); return 0; } Output: string empty Why and how so? Programming in C programming-in-c + – Reshu $ingh 545 views answer comment Share Follow Print 0 reply Please log in or register to add a comment.
Best answer 3 3 votes Program 1. Return value of printf() -> No. of characters printed on the standard output char a[] contains NULL string i.e. the character '\0'. When printft() is executed , it prints nothing, ie printf() returns 0 (No. of characters printed are zero). Hence the if body isn't executed. Program 2. char a[] contains string of length 1, ie a 'space character'. When printf() is executed, prints the space character onto the console, returns 1 (No. of characters printed). 'if' condition evaluates to TRUE. allSystemsDown answered Apr 1, 2019 • selected May 29, 2019 by Reshu $ingh allSystemsDown comment Share Follow 0 reply Please log in or register to add a comment.