Home Misc How to print something without using even a single semicolon?

How to print something without using even a single semicolon?

by nikoo28
0 comment

The general way to print any statement would be like:-

#include<stdio.h>
int main(void)
{
    printf("Hi! There...");
}

But in this example we are using at least one semicolon(;).

Our target is to print something on the screen without using even a single semi colon(;) . This is sort of a fun problem rather than an actual concept. It may seem to be impossible at once but we can utilize the fact that the statements inside an if condition is always executed and its result is used to determine the block to be executed.
We can do something like this:-

#include<stdio.h>
int main(void)
{
    if( printf("Hi! There...") )
    {
        // Do nothing
    }
}

This will print without having used a semicolon.
One trivial extension of the above problem: Write a C program to print “;” without using a semicolon.

#include<stdio.h>
int main()
{
    if( printf("%c",59) ) // We use the ascii value
    {
        // Do Nothing
    }
}

Feel free to share other methods in comments below.

You may also like

Enclose codes in [code lang="JAVA"] [/code] tags

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More