C++ Programming Basics
Introduction
C++ is a general-purpose programming language created by Bjarne Stroustrup as an
extension of the C language. It supports procedural, object-oriented, and generic
programming features, making it one of the most widely used languages for software
development.
Getting Started
To write and run C++ code, you need a compiler such as g++ (GNU Compiler
Collection) or the compiler provided with Visual Studio.
Basic Syntax
A simple C++ program:
#include <iostream>
using namespace std;
int main() {
cout << "Hello, World!" << endl;
return 0;
}
Key Concepts
1. Variables and Data Types
int age = 25;
double height = 1.75;
char grade = 'A';
bool isStudent = true;
2. Control Structures
if (age > 18) {
cout << "Adult";
} else {
cout << "Minor";
}
for (int i = 0; i < 5; i++) {
cout << i << endl;
}
3. Functions
int add(int a, int b) {
return a + b;
}
4. Object-Oriented Programming
class Car {
public:
string model;
int year;
void display() {
cout << model << " - " << year << endl;
}
};
int main() {
Car car1;
car1.model = "Toyota";
car1.year = 2020;
car1.display();
return 0;
}
Conclusion
C++ remains a relevant and powerful language, suitable for systems programming,
game development, and performance-critical applications.