top of page

Semicolons and Blocks in C++

  • Writer: -A
    -A
  • Jan 25, 2020
  • 1 min read

In C++, the semicolon is a statement terminator. That is, each individual statement must be ended with a semicolon. It indicates the end of one logical entity.

For example, following are three different statements −

x = y;
y = y + 1;
add(x, y);

A block is a set of logically connected statements that are surrounded by opening and closing braces. For example −

{
   cout << "Hello World"; // prints Hello World
   return 0;
}

C++ does not recognize the end of the line as a terminator. For this reason, it does not matter where you put a statement in a line. For example −

x = y;
y = y + 1;
add(x, y);

is the same as

x = y; y = y + 1; add(x, y);

Comments


Post: Blog2_Post

Subscribe Form

Thanks for submitting!

  • Instagram
  • Facebook

©2020 by C++ Programming. Proudly created with Wix.com

bottom of page