VOOZH about

URL: https://www.geeksforgeeks.org/cpp/print-hello-world-without-semicolon-in-ccpp/

⇱ Print Hello World without semicolon in C/C++ - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Print Hello World without semicolon in C/C++

Last Updated : 13 Mar, 2023
Every statement in C++ must end with a semicolon as per basics. However, unlike other languages, almost all statements in C++ can be treated as expressions. However there are few scenarios when we can write a running program without semicolon. If we place the statement inside an if/switch/while/macro statement with a blank pair of parentheses, we don’t have to end it with a semicolon. Also, calling a function that returns void will not work here as void functions are not expressions. We can although use a comma operator, with any value in the right hand side of the operator. Examples:
  1. Using if statement: Output:
    Hello World
  2. Using switch statement: Output:
    Hello World 
  3. Using macros Output:
    Hello World 
  4. Using loops (while and for) : Here, important thing to note is using !(not operator) in while loop to avoid infinite loop.
Comment
Article Tags:
Article Tags: