Introduction to Semicolon in C++ :: Part-A-10



In C++, the semicolon is used as a statement terminator. Every statement must end with a semicolon. This is different from other languages, notably Pascal, which use the semicolon as a statement separator. Note that lines that begin with the pound symbol # such as

                   #include <iostream.h>

do not end with a semicolon because they are not statements; they are preprocessing directives.

We saw in the previous section that C++ statements can be interpreted as expressions. The converse is also true: expressions can be used as stand-alone statements. For example, here are two perfectly valid C++ statements:

                    x + y;


These statements perform no actions, so they are completely useless. Nevertheless they are valid statements in C++. We shall see some useful expression statements later.

The semicolon acts like an operator on an expression. It transforms an expression into a statement. It is not a true operator because its result is a statement, not a value. But this transformation point of view helps explain the difference between an expression and a statement.

                                                                               ——————- Thanks


About Author


Leave A Reply