C++ is a powerful general-purpose programming language that is widely used for system/software development, game development, and competitive programming.
C++ syntax is structured and efficient. Below is a basic example:
#includeusing namespace std; int main() { cout << "Hello, World!" << endl; return 0; }
C++ supports various data types such as int, float, double, and string.
int age = 25;
double pi = 3.1415;
string name = "Alice";
cout << "Name: " << name << ", Age: " << age << endl;
Functions in C++ allow you to modularize your code:
int add(int a, int b) {
return a + b;
}
int main() {
cout << "Sum: " << add(5, 3) << endl;
return 0;
}
C++ supports object-oriented programming:
class Car {
public:
string brand;
int year;
void display() {
cout << "Brand: " << brand << ", Year: " << year << endl;
}
};
int main() {
Car myCar;
myCar.brand = "Toyota";
myCar.year = 2022;
myCar.display();
return 0;
}
Pointers allow direct memory access:
int x = 10;
int* ptr = &x;
cout << "Value: " << *ptr << endl;
There are many online resources to learn C++:
Practice is key to mastering C++. Start coding today!
Try C++