Introduction to C++
Programming
Learn the Basics of C++ with Ease
What is C++?
• - A powerful, general-purpose programming
language.
• - Supports procedural and object-oriented
programming.
• - Used for system programming, game
development, etc.
Basic Structure of a C++ Program
• #include <iostream>
• using namespace std;
• int main() {
• // Code goes here
• return 0;
• }
Variables and Data Types
• - Variables store data values.
• - Common data types:
• * int: Integer (e.g., int x = 10;)
• * float: Floating point (e.g., float y = 3.14;)
• * char: Character (e.g., char c = 'A';)
Input and Output
• - cin: Input from user (e.g., cin >> x;)
• - cout: Output to screen (e.g., cout << "Hello
World";)
Conditional Statements
• - if-else:
• if (x > 0) {
• cout << "Positive";
• } else {
• cout << "Negative";
• }
• - switch-case: Handles multiple conditions.
Loops
• - for loop: Repeats a block of code.
• - while loop: Repeats while a condition is true.
• - do-while: Executes at least once.
Functions
• - Reusable blocks of code.
• - Syntax:
• return_type function_name(parameters) {
• // Code
• }
• - Example: int add(int a, int b) { return a + b; }
Arrays
• - Stores multiple values of the same type.
• - Syntax: data_type array_name[size];
• - Example: int arr[5] = {1, 2, 3, 4, 5};
Object-Oriented Programming
(OOP) Basics
• - Class: Blueprint for objects.
• - Object: Instance of a class.
• - Example:
• class Car {
• public:
• string brand;
• void display() {
• cout << brand;
• }
Conclusion
• - C++ is a powerful and versatile language.
• - Mastering its basics is key to advanced
programming.
• - Practice regularly to strengthen your
understanding.