+ 6

How to print Hello in c without using semicolon ?😉😉😉

13th Feb 2019, 5:48 PM
Shakti Vishwakarma
Shakti Vishwakarma - avatar
7 Antworten
+ 4
Well, I found two ways to do it. One by myself, and the other one is googled stuff. So I am myself trying to figure out how does it work. First one is pretty simple. #include <stdio.h> int main() { if(printf("hello world")) { } } The second one is: https://code.sololearn.com/cAi6wHx0KAvk/?ref=app If someone knows how does the second code work, then please answer this: https://www.sololearn.com/Discuss/1689859/?ref=app
15th Feb 2019, 3:27 PM
Abhishek Tandon
Abhishek Tandon - avatar
+ 3
printf returns the total number of characters it prints. Here, "hello world" has 11 characters, so printf will return 11. Now, the statement is reduced to if(11) { } which is true because if(0) is false, and for other numbers other than 0, its true. This is how it works!
16th Feb 2019, 5:32 AM
Abhishek Tandon
Abhishek Tandon - avatar
+ 3
printf() is a function with return type 'int', so it does both the job. It prints what you send it inside the braces in double quotes and returns the number of characters it just printed on the screen.
17th Feb 2019, 6:53 AM
Abhishek Tandon
Abhishek Tandon - avatar
+ 2
https://code.sololearn.com/cVK9AnFXkzf5/?ref=app Check my code.
13th Feb 2019, 7:17 PM
Kuldeep Pathak
Kuldeep Pathak - avatar
+ 2
How first work ?
16th Feb 2019, 4:37 AM
Shakti Vishwakarma
Shakti Vishwakarma - avatar
0
Ok it is returning number of char but why it is printing on desktop we are just taking it as argument
17th Feb 2019, 6:13 AM
Shakti Vishwakarma
Shakti Vishwakarma - avatar