C++ Syntax

C++ syntax refers to the rules and structure used to write C++ code. These rules define how we should organize and structure our code, including how we declare variables, create functions, and write control flow statements.

Example:


#include <iostream>  // Preprocessor directive to include the standard input-output library

using namespace std;  // Declares the standard namespace

// Main function - execution starts here
int main() {
    // Statements
    cout << "Hello, Friends!" << endl;  // Output a message to the console
    return 0;  // Exit status of the program
}

Explanation:

include: A preprocessor directive that includes header files (such as iostream for input/output).

using namespace std;: This line tells the compiler to use the std (standard) namespace, which contains standard library features like cout.

main(): The main function is where the program starts executing.

return 0;: Returns 0 to indicate successful execution.

Note: In C++, each statement ends with a semicolon (;).