How to print a semicolon(;) without using semicolon in C/C++?

Another interesting question is how can a semicolon be printed without using any semicolon in the program. Here are methods to print “;” :

  1. Using printf / putchar in if statement:
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    // CPP program to print 
    // ; without using ;
    // using if statement
    #include <stdio.h>
    int main()
    {
        // ASCII value of semicolon = 59
        if (printf("%c\n", 59))
        if (putchar(59))
        {
        }
        return 0;
    }

    chevron_right

    
    

    Output:

    ;
    ;
    

    We can also print the semicolon using switch/ while / for as illustrated in this article.

  2. Using macros :
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    // CPP program to print 
    // ; without using ;
    // using macros
    #include <stdio.h>
    #define GEEK printf("%c",59)
    int main()
    {
        if (GEEK)
        {
        }
    }

    chevron_right

    
    

    Output:



    ;
    

Related article: Print Hello World without semicolon in C/C++

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.



My Personal Notes arrow_drop_up


Article Tags :
Practice Tags :


2


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.