Read this code snippet :
void main() { int i; char a[]="\0"; if(printf("%s\n",a)) printf(" GATE 2018\n"); else printf("Forget GATE\n"); }
The output is :
yes, due to '\n' the condition part of if() becomes true .
here i remove '\n' , now it becomes https://ideone.com/y6aibK
gives out put
Forget GATE
Because of \n inside printf condition will become true (\n is newline character so it will print nothing but will insert a new line) and output will be GATE 2018.
void main() { int i; char a[]="\0"; if(printf("%s",a)) printf(" GATE 2018\n"); else printf("Forget GATE\n"); }
Now output will be : Forget GATE
Some ref : https://stackoverflow.com/questions/18654465/how-0-is-treated-in-printf#:~:text=So%20empty%20is%20printed%20as%20output.&text=The%20main%20concept%20here%20is,in%20the%20statement%20if%20any%20
64.3k questions
77.9k answers
244k comments
80.0k users