1.
Data Types
Data types specify the type of data a variable can hold in C++. Common data types include int,
float, char, bool, and double.
Why Use This?
To store and manipulate different types of data efficiently.
Common Mistakes:
Assigning values exceeding the range of a data type (e.g., assigning a large number to int).
2. Increment and Decrement Operators
Operators used to increase (++) or decrease (--) the value of a variable by 1.
Why Use This?
Simplifies repetitive addition or subtraction.
Useful in loops for iteration.
Common Mistakes:
Using increment/decrement on non-integer data types.
3. Operators
Operators perform operations on variables and values. They include arithmetic, assignment and
logical.
Why Use This?
To perform mathematical computations.
Common Mistakes:
Misusing logical operators (&&, ||).
4. C++ Main Function
The main() function is the entry point of every C++ program.
Why Use This?
It acts as the starting point for execution.
Common Mistakes:
Forgetting the return 0; statement (though optional in modern compilers).
5. C++ cin and cout with Namespace
cin and cout are used for input and output operations in C++.
Why Use This?
cin takes input from the user.
cout displays output to the console(programs black screen).
Common Mistakes:
Forgetting to include #include <iostream>.
6. Conditional Statements
Conditional statements (if, else, else if) are used to make decisions based on conditions.
Why Use This?
To control the flow of the program.
Enables decision-making.
Common Mistakes:
Misplacing curly braces.
7. Loops
While Loop:
Executes a block of code repeatedly as long as the condition is true.
Why Use This?
When the number of iterations is unknown.
Common Mistakes:
Infinite loops due to incorrect conditions.
Do-While Loop
Executes the block at least once before checking the condition.
Why Use This?
Ensures code runs at least once.
Common Mistakes:
1. Forgetting the semicolon after the while condition.
For Loop
Used when the number of iterations is known.
Why Use This?
Simplifies loop initialization, condition, and increment in one line.
Common Mistakes:
Off-by-one errors in loop bounds.
8. Arrays
A collection of elements of the same data type stored in contiguous memory.
Why Use This?
To store multiple values in a single variable.
Common Mistakes:
Accessing out-of-bound indexes.
9. Switch Case Statement
Simplifies multi-conditional checks.
Why Use This?
Efficient alternative to multiple if-else statements.
Common Mistakes:
Forgetting the break statement.
10. const Keyword
Declares variables as constant and prevents modification.
Why Use This?
Ensures variables are not changed during the program.
Common Mistakes:
Attempting to modify const variables.
11. Functions
A block of reusable code.
Why Use This?
Improves structure of program and reusability.
Common Mistakes:
1. Call that name of a function which does not exist.