Cover Image for Print “Hello” without ; in C
95 views

Print “Hello” without ; in C

You can print “Hello” without using a semicolon (;) in C by taking advantage of the fact that the if statement doesn’t require a semicolon immediately after it. Here’s a creative way to achieve it:

C
#include <stdio.h>

int main() {
    if (printf("Hello")) {}
    return 0;
}

In this program:

  • We use printf("Hello") as the condition in the if statement.
  • The printf function prints “Hello” to the console.
  • Since the if statement doesn’t need a semicolon immediately after it, we don’t use one.

When you run this program, it will print “Hello” to the console without using a semicolon after printf("Hello"). However, this approach is not recommended for real-world code as it’s not idiomatic and may confuse other programmers who read your code. Semicolons are essential for proper statement termination in C, and it’s best to use them as intended.

YOU MAY ALSO LIKE...

The Tech Thunder

The Tech Thunder

The Tech Thunder


COMMENTS