Skip to Content

Step by Step C++ Beginner Guide


1. History of C++

Creator: Bjarne Stroustrup
Year: Started in 1979, first released in 1985
Why Created:
C language was very fast but lacked some features like classes, objects, data security.
Bjarne wanted a language with both speed of C and features of Object-Oriented Programming (OOP).
Use:
System software (like operating systems)
Game development
Browsers (e.g., Chrome uses C++)
Database engines (MySQL, MongoDB)
Embedded systems


2. Basic Structure of a C++ Program

#include <iostream>
using namespace std;

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

3. Step-by-step Reading and Explanation

Line 1: #include <iostream>
Read as: "Hashtag include iostream"
(called "hash" or "preprocessor symbol") → tells compiler to include something before compilation.
include → means add a library.
<iostream> → this is a header file (input-output stream), it allows us to use cin (input) and cout (output).
Meaning: "Bring tools for input and output into my program."

Line 2: using namespace std;
Read as: "using namespace standard semicolon"
using → tells compiler we want to use something.
namespace → is like a box of code (a collection).
std → short for standard (the default box of code).
; → semicolon ends a statement (like a full stop in English).
Meaning: "Use the standard C++ tools without writing std:: every time."

Line 3: int main() {
Read as: "int main open round bracket close round bracket open curly bracket"
int → return type (function will give an integer number at end).
main → the starting point of every C++ program (execution begins here).
() → parentheses (means no input parameters given here).
{ → curly bracket opens → start of function body.
Meaning: "Here begins the main program."

Line 4: cout << "Hello, World!";
Read as: "see-out shift-left double-quote Hello World double-quote semicolon"
cout → character output (used to print on screen).
<< → "insertion operator" (sends data to output).
"Hello, World!" → string (text inside double quotes).
; → end of command.
Meaning: "Print Hello, World! on the screen."

Line 5: return 0;
Read as: "return zero semicolon"
return → send a value back.
0 → means successful execution (no error).
; → statement end.
Meaning: "Tell the operating system program ended successfully."

Line 6: }
Read as: "close curly bracket"
Ends the main function.
Meaning: "Program finished here."


4. 🔣 C++ Symbols — How to Read & Meaning

SymbolRead AsMeaning
#Hashtag / SharpPreprocessor instruction (#include)
;SemicolonEnd of a statement
{Curly bracket openStart of a block/function/class
}Curly bracket closeEnd of a block/function/class
()Round bracket open/closeFunctions, conditions, arguments
[]Square bracket open/closeArrays / indexing
<<Less than less thanInsert data into output (cout)
>>Greater than greater thanExtract data from input (cin)
" "Double quoteDenotes a string
' 'Single quoteDenotes a single character
//Double slashSingle-line comment
/* ... */Slash-star … star-slashMulti-line comment
=EqualsAssignment operator
+ - * / %Plus, minus, multiply, divide, moduloArithmetic operations
++Plus plusIncrement by 1
--Minus minusDecrement by 1
==Equals equalsCheck equality
!=Not equalCheck inequality
< > <= >=Comparison operatorsLess than / Greater than / Less equal / Greater equal
&&AndLogical AND
||OrLogical OR
!NotLogical NOT
:ColonUsed in labels, ternary operator, inheritance
?:Question mark colonTernary operator (if-else in one line)
.DotAccess object member
->ArrowAccess pointer object member
::Double colonScope resolution (std::cout)
\nBackslash nNew line
\tBackslash tTab / spacing

5. 🆔 C++ Identifiers & Basics — Beginner Friendly Guide

1. What is an Identifier?

An identifier is a name you give to anything in C++ like variables, functions, classes, objects, constants, etc. It helps you refer to that item in your program.

2. What is a Data Type?

A data type tells the computer what kind of value a variable can store.

int age = 18;
float salary = 5000.5;
char grade = 'A';

👉 age, salary, grade = identifiers
👉 int, float, char = data types
👉 18, 5000.5, 'A' = values

3. What is an Operator?

Operators are symbols that perform operations on data.

  • + → Addition
  • - → Subtraction
  • * → Multiplication
  • / → Division
  • = → Assignment

4. What is a Value?

A value is the actual data stored in a variable.

18, 3.14, 'A', 5000

5. What is a Keyword?

Keywords are reserved words in C++ that have a special meaning and cannot be used as identifiers.

int, float, char, 
if, else, return

6. 📝 C++ Naming Rules — Complete Step-by-Step Guide

1. General Rules for All Identifiers

  • Names must begin with a letter (A–Z, a–z) or underscore (_).
  • Names can contain letters, digits (0–9), and underscores.
  • Names cannot start with a digit.
  • Names cannot use spaces or special characters (@, $, %, -).
  • Names cannot be a C++ keyword (like int, for).
  • C++ is case-sensitiveValue and value are different.
  • Names should be meaningful for readability.
// ✅ Correct
int age;
float monthly_salary;
char gradeA;

// ❌ Wrong
int 1value;   // cannot start with number
float salary$; // invalid symbol
char for;       // keyword not allowed

2. Variable Naming Rules

RuleExample ✅Bad ❌
Use lowercase or camelCasestudentAgex
Can use underscore for claritytotal_salaryts

3. Constant Naming Rules

  • Use ALL_CAPS with underscores for constants.
const double PI_VALUE = 3.1416;
const int MAX_STUDENTS = 100;

4. Function Naming Rules

  • Use camelCase or snake_case.
  • Name should describe an action.
int addNumbers(int a, int b) {
    return a + b;
}

5. Class & Object Naming Rules

EntityConventionExample
ClassPascalCaseStudentRecord
ObjectcamelCasestudent1
class CarModel {
   public:
   void startEngine() {}
};

CarModel myCar;

6. Array Naming Rules

  • Arrays should be plural.
int marks[5];
string names[10];

7. Pointer & Reference Naming Rules

  • Pointers: use p or ptr prefix.
  • References: use ref suffix.
int value;
int* pValue = &value;
int& valueRef = value;

8. Namespace Naming Rules

  • Use lowercase for namespaces.
namespace school {
    int students = 50;
}

9. Enum Naming Rules

  • Enum type: PascalCase
  • Enum values: ALL_CAPS
enum Color { RED, GREEN, BLUE };

10. Template Naming Rules

  • Use single capital letters (T, U, V) for template parameters.
template <typename T>
class Box {
    T value;
};

11. Label Naming Rules

  • Labels should be simple and descriptive.
startLoop:
for (int i = 0; i < 5; i++) {
    if (i == 3) goto startLoop;
}

12. Typedef / Using Naming Rules

typedef unsigned int uint;
using Age = int;

13. Macro Naming Rules

  • Use ALL_CAPS for macros.
#define PI 3.14159
#define MAX 100

7. 🔑 Complete C++ Keywords (with Meanings)

C++ keywords are reserved words. They cannot be used as identifiers (variable names, class names, etc.). Here’s the latest list with meanings (C++98 → C++11 → C++20 → C++23).

1. Data Types

KeywordMeaning
boolBoolean type (true/false)
charCharacter type (1 byte)
char8_tUTF-8 character type (added in C++20)
char16_tUTF-16 character type (added in C++11)
char32_tUTF-32 character type (added in C++11)
intInteger type
longLong integer
shortShort integer
signedSigned modifier (can be + or -)
unsignedUnsigned modifier (only positive)
floatSingle-precision floating number
doubleDouble-precision floating number
voidNo return / empty type
wchar_tWide character type

2. Storage Class & Type Modifiers

KeywordMeaning
constConstant (cannot change value)
volatilePrevents compiler optimization
mutableAllows modification inside const object
autoType deduced automatically
registerSuggest store in CPU register (deprecated)
staticPreserves value between function calls
externVariable defined outside file
thread_localEach thread has its own instance

3. Control Flow

KeywordMeaning
if, elseConditional branching
switch, case, defaultMulti-branch selection
while, do, forLooping statements
breakExit from loop/switch
continueSkip current loop iteration
gotoJump to label (not recommended)
returnReturn value from function

4. Functions & Exception Handling

KeywordMeaning
try, catch, throwException handling
noexceptSpecifies function won’t throw exceptions
operatorDefines custom operator overloading
explicitPrevents implicit type conversion
friendAllows access to private members
inlineSuggests inline expansion of function
virtualDefines virtual function for polymorphism
overrideEnsures function overrides base version
finalPrevents further inheritance/overriding

5. Object-Oriented Keywords

KeywordMeaning
class, struct, unionDefine user-defined types
enumDefine enumerations
private, protected, publicAccess specifiers
thisPointer to current object
new, deleteDynamic memory allocation & deallocation

6. Casting Operators

KeywordMeaning
dynamic_castSafe downcasting (runtime check)
const_castModify const-ness
reinterpret_castConvert one pointer type to another
static_castCompile-time conversion

7. Type Information

KeywordMeaning
sizeofReturns size of type/variable
decltypeInfers type of expression
typeidGives runtime type info
alignof, alignasMemory alignment

8. Namespace & Templates

KeywordMeaning
namespaceDefines scope grouping
usingAlias or bring namespace into scope
templateGeneric programming
typenameDefines template type parameter
concept, requiresConstraints in templates (C++20)

9. Coroutines (C++20)

KeywordMeaning
co_awaitSuspends coroutine until ready
co_yieldProduces a value from coroutine
co_returnReturns from coroutine

10. Boolean & Literals

KeywordMeaning
true, falseBoolean constants
nullptrNull pointer literal (C++11)

11. Alternative Operator Keywords

C++ also provides alternative spellings for operators:

KeywordEquivalent
and&&
or||
not!
bitand&
bitor|
xor^
compl~
and_eq&=
or_eq|=
xor_eq^=
not_eq!=

🔢 Total Keywords

C++98: 64 keywords
C++11: +10 new
C++20: +7 new
C++23: +2 new
Alternative Operators: 11

Total Reserved Keywords = 94