C++ Basic Notes
Introduction to C++
C++ is a general-purpose programming language created by Bjarne Stroustrup as an extension of
the C programming language. It supports both procedural and object-oriented programming,
making it versatile for various applications.
Basic Structure of a C++ Program
A basic C++ program consists of: 1. Preprocessor directives (#include) 2. Namespace declaration
3. main() function 4. Statements and expressions 5. Return statement
Data Types
• int - Integer numbers
• float - Floating point numbers
• double - Double-precision floating point numbers
• char - Single characters
• string - Sequence of characters
• bool - Boolean values (true/false)
Variables and Constants
Variables are used to store data. They must be declared before use. Constants are fixed values
that cannot be changed.
Operators
• Arithmetic: +, -, *, /, %
• Relational: ==, !=, >, <, >=, <=
• Logical: &&, ||, !
• Assignment: =, +=, -=, *=, /=
• Increment/Decrement: ++, --
Control Structures
• if, if-else, nested if
• switch-case
• for loop
• while loop
• do-while loop
Functions
Functions are blocks of code that perform a specific task. They help in code reusability and better
organization.
Object-Oriented Programming Concepts
• Class and Object
• Encapsulation
• Inheritance
• Polymorphism
• Abstraction