Introduction

C++ is a powerful and flexible programming language that supports procedural, object-oriented, and generic programming. It provides a rich set of features including classes, templates, exception handling, and a strong type system. Understanding the basic syntax and data types is fundamental before diving into more advanced topics. The structure and syntax of a C++ program determine how the compiler interprets and executes the code. Data types define the type of data a variable can hold and how much memory it occupies.

Structure of a C++ Program

A basic C++ program generally includes the following components:

  • Preprocessor directives
  • Namespace declaration
  • The main() function
  • Statements inside the main function
  • Return statement indicating the exit status

 

General Syntax:

#include using namespace std;

int main() {

// Statements

return 0; }

 

Example:

#include using namespace std;

int main() {

cout << “Hello, World!” << endl;

return 0; }

Tokens in C++

Tokens are the smallest individual units in a C++ program. The compiler breaks the program into tokens for processing. C++ has the following types of tokens:

  1. Keywords: Reserved words with special meaning

e.g., int, return, while

  1. Identifiers: Names given to variables, functions, arrays, etc.

e.g., age, totalSum

  1. Constants: Fixed values that do not change during execution

e.g., 5, ‘A’, 3.14

  1. Operators: Symbols that perform operations on variables and values

e.g., +, -, *, /

  1. Separators: Symbols used to structure code

e.g., ; { } ( )