Open In App

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

Last Updated : 14 Jun, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

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
CPP
// 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;
}

Output:

;
;
  1. We can also print the semicolon using switch/ while / for as illustrated in this article.
  2. Using macros : 
CPP
// CPP program to print 
// ; without using ;
// using macros
#include <stdio.h>
#define GEEK printf("%c",59)
int main()
{
    if (GEEK)
    {
    }
}

Output:

;

3. Using std::cout

C++
#include <iostream>

// 59 is an ASCII value of the semicolon
#define SEMICOLON 59

int main()
{
    if (std::cout << static_cast<char>(SEMICOLON)) {
    }
}

Output
;

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


Next Article
Practice Tags :

Similar Reads