+ 10

How to code to print"hello world" without semicolon in C ?

2nd Dec 2018, 4:09 PM
Ratnapal Shende
Ratnapal Shende - avatar
11 Antworten
+ 11
#include <stdio.h> int main() { if(printf("Hello World")) return 0; }
2nd Dec 2018, 4:53 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 7
if (printf("Hello world!")) {}
2nd Dec 2018, 4:36 PM
HonFu
HonFu - avatar
+ 3
#include<stdio.h> void main(){ if(printf("hello world")){} }
2nd Dec 2018, 4:37 PM
AL Araf
AL Araf - avatar
+ 3
Shikha main also returns a number at the end, default 0, to indicate success. You can use return 1; (or any other number other then 0) to indicate an error and end the program. Which in C, with all the many segmentation faults that are possible, is very helpful. HonFu okay I thought so, just for fun then.
4th Dec 2018, 4:40 PM
Djjohnsongeek
+ 2
Why we only use main function to start the program?
4th Dec 2018, 3:30 PM
Shikha
Shikha - avatar
+ 1
When you want to end a state in a line and go to the next line you should put semicolon at the end of the line.[in C you should put semicolons at the end of every lines(except after curly braces and loop statements)]
2nd Dec 2018, 4:26 PM
Ali Rayat
Ali Rayat - avatar
+ 1
In C, any void returning statement is true. You could try that.
2nd Dec 2018, 10:24 PM
LiquidX
LiquidX - avatar
+ 1
Just curious, is there a reason this is useful?
3rd Dec 2018, 5:37 PM
Djjohnsongeek
+ 1
Not really I think. 😏
3rd Dec 2018, 5:46 PM
HonFu
HonFu - avatar
+ 1
Shikha, it's just how the language is designed. A program has to start somewhere, right? In Java you even start the program from a whole main class instead of just a function; in Python you just start with the code in line 1.
4th Dec 2018, 3:33 PM
HonFu
HonFu - avatar