In the world of programming there are languages that have stood the test of time and still power today's most in-demand technologies. One of them is C++.
Operating systems (the Windows, Linux and macOS kernels), browser engines (V8, Chromium), modern 3D game engines (Unreal Engine) and high-frequency trading systems (HFT) are all written in C++.
1. The basic structure of C++
Every C++ program starts with the main() function. Here is the simplest program:
#include <iostream>
using namespace std;
int main() {
// Standart konsolga matn chiqarish
cout << "Salom, ALGOR platformasi!" << endl;
return 0;
}
#include <iostream>— the standard library for input and output streams.int main()— the program's entry point.
2. Data types, input and output
C++ is statically typed, and every variable occupies its own amount of memory:
int son = 42; // 4 bayt (-2*10^9 dan 2*10^9 gacha)
long long katta_son = 1e18; // 8 bayt (juda katta sonlar uchun)
double pi = 3.14159; // 8 bayt (haqiqiy sonlar)
char belgi = 'A'; // 1 bayt
bool holat = true; // 1 bayt
// Konsoldan son o'qish
cin >> son;
3. Pointers — the real power of C++
A pointer is a special variable that stores the address of another variable in the computer's memory (RAM).
int x = 100;
int* ptr = &x; // ptr x ning xotiradagi manzilini saqlaydi
cout << "x ning qiymati: " << x << endl;
cout << "x ning xotiradagi manzili: " << ptr << endl;
cout << "Ko'rsatkich orqali qiymatni o'qish: " << *ptr << endl;
Understanding pointers gives a programmer a deep feel for how computer hardware actually works.
4. Object-oriented programming (OOP)
C++ offers full OOP support:
- Encapsulation: bundling data and methods together inside a single class.
- Inheritance: passing properties from one class to another.
- Polymorphism: working with different objects through one interface.
class Foydalanuvchi {
private:
string ism;
int reyting;
public:
Foydalanuvchi(string n, int r) : ism(n), reyting(r) {}
void malumot() {
cout << ism << " — Reyting: " << reyting << endl;
}
};
5. C++ in competitive programming
Why do 90% of ICPC and Codeforces participants choose C++?
Because with C++ you can comfortably perform $10^8$ (100 million) operations per second. On top of that, the ready-made STL (Standard Template Library) containers — vector, set, map, priority_queue — let you write algorithms in seconds.
To strengthen your C++ skills, head to the ALGOR problems section and submit your first code!