Site icon TestingDocs.com

Basic C++ Syntax

Overview

In this tutorial, we will learn basic C++ syntax. C++ syntax is much similar to C, Java.

Statement Terminator

In C++, the semicolon is the statement terminator. Each code statement
should end with a semicolon.

Examples:

int a ;

a = 10;

We can even write two statements in a single line.

int a; a = 10;

C++ Comments

Single line comments start with a //

Multi-line comments start with /* and end with */

 

Code blocks

A code block is a set of logically grouped statements that are surrounded by opening and closing braces. We use curly braces to denote a code block in the C++ program.

The main function or routine block is denoted by the curly braces. The source code formatting can have different options and styles.

Allman (ANSI) Bracket style:

The curly braces are placed in the next line and the code block statements are indented to the next level.

 

int main()
{
    cout << "Hello, World!";
    return 0;
}

C++ Tutorials

C++ Tutorials on this website:

https://www.testingdocs.com/c-coding-tutorials/

For more information on the current ISO C++ standard

https://isocpp.org/std/the-standard

Exit mobile version