Guide to C++ Fundamentals
Guide to C++ Fundamentals
Fundamentals
By Eslam Linux
Table of Contents
1. Introduction
2. Setting Up Your Environment
3. C++ Syntax and Structure
4. Variables and Data Types
5. Operators and Expressions
6. Control Flow Statements
7. Functions in C++
8. Arrays and Pointers
9. Object-Oriented Programming Basics
10.Input and Output
11.Error Handling and Debugging
12.Advanced Concepts Overview
13.Conclusion
Chapter 1: Introduction
C++ is a versatile programming language renowned for its performance and control. Developed by
Bjarne Stroustrup in 1983, C++ combines the power of low-level programming with the simplicity
of high-level abstractions. This guide will introduce you to the core concepts of C++ programming,
providing a solid foundation to advance into more complex projects.
• Performance : C++ delivers unparalleled speed and efficiency, making it ideal for game
development, system software, and real-time applications.
• Object-Oriented Programming (OOP) : C++ is one of the pioneers of OOP, enabling clear
and modular code design.
• Versatility : From operating systems to video games, C++ is used in a variety of
applications.
Installing a Compiler
To run C++ programs, you'll need a compiler. Popular choices include:
• GCC (GNU Compiler Collection) : Widely used and free, available on Linux, macOS, and
Windows.
• MS Visual C++ : A robust compiler that integrates with Visual Studio on Windows.
Choosing an IDE
An Integrated Development Environment (IDE) simplifies coding with features like syntax
highlighting and debugging tools. Recommended IDEs are:
• Visual Studio
• Code::Blocks
• CLion
int main() {
cout << "Hello, World!" << endl;
return 0;
}
Comments
C++ supports single-line ( // ) and multi-line ( /* */ ) comments to document code.
Chapter 4: Variables and Data Types
Variables store data, and C++ has a variety of types:
Example:
cppCopy code
int age = 25;
float price = 19.99;
char grade = 'A';
bool isAvailable = true;
• Arithmetic Operators : + , - , * , / , %
• Relational Operators : == , != , < , > , <= , >=
• Logical Operators : && , || , !
Example:
cppCopy code
int a = 10, b = 20;
cout << (a + b); // Outputs 30
• If-Else Statement :
cppCopy code
if (x > 10)
cout << "x is greater than 10";
else
cout << "x is 10 or less";
• For Loop :
cppCopy code
for (int i = 0; i < 5; i++)
cout << i;
• Array Example :
cppCopy code
int numbers[5] = {1, 2, 3, 4, 5};
cout << numbers[0]; // Outputs 1
• Pointer Example :
cppCopy code
int x = 10;
int* ptr = &x;
cout << *ptr; // Outputs 10
• Defining a Class :
cppCopy code
class Car {
public:
string brand;
void honk() { cout << "Honk!"; }
};
• Using Objects :
cppCopy code
Car myCar;
myCar.brand = "Toyota";
myCar.honk(); // Outputs "Honk!"
• Input Example :
cppCopy code
int age;
cin >> age;
cout << "Your age is " << age;
• Templates
• STL (Standard Template Library)
• Multithreading
• File Handling