How to print hello world without semi colon in C?

We can print hello world without using semi colon using if condition in C program as below.

“if (printf("Hello World")) ;”


Intent of the question is that we can print values on console screen using printf function as shown in below program.

int main(){
	printf("hello world");

	return 0;

Output: hello world

But, how you can print hello world without semi colon? Meaning, we don’t have to use semi colone i.e. ; after the printf(“hello world”) function as shown in code example above. Semi colon is there as a closing statement.

Off course, we have to use printf statement but, since, we don’t want to use semi colone, we can write printf function inside an if condition as given below.

if (printf(“hello world”)) ;

C Code:

int main(){
	if (printf("hello world")) ; 

	return 0;

Note that we are calling “printf(“hello world”)” function inside if condition. We have not used ; after printf function call. We have used after if condition.


prinf function in C code returns number of characters present in the string. So, in above example, printf will return value 11 as “hello world” length is 11 chars including space.

So, if(11) should be ok and program runs fine.

Leave a Comment