program to print "Hello World" without using semicolon anywhere in the code.

29 Dec 2022 Balmiki Kumar 0 C Programming

Program to print "Hello World" without using a semicolon anywhere in the code.

Generally when we use printf("") statement, we have to use a semicolon at the end. If printf is used inside an if condition, semicolons can be avoided.

Program: C Program to print something without using a semicolon(;)

#include<stdio.h>
int main() {
 //printf returns the length of string being printed
 if (printf("Hello World\n")) //prints Hello World and returns 11
 {
 //do nothing
 }
 return 0;
}

Output:

Hello World

Explanation:

The if statement checks for the condition of whether the return value of printf("Hello World") is greater than 0. printf function returns the length of the string printed. Hence the statement if (printf("Hello World")) prints the string "Hello World".

BY: Balmiki Kumar

Related Blogs

Post Comments.

Login to Post a Comment

No comments yet, Be the first to comment.