What is C++? 🚀
C++ is a powerful programming language that was created in 1983 based on C. It combines speed, memory control, and object-oriented programming. 💡
Many well-known programs are written in C++, including game engines (Unreal Engine), operating systems, and even banking software. If you want to develop games, high-performance applications, or delve into programming, C++ is a great choice! 🎮
How to start programming in C++? 💻
To work with C++ you will need:
✅ Compiler, for example Microsoft Visual Studio or Code::Blocks.
✅ Text editor, for example Visual Studio Code.
✅ Installed GCC compiler (can be set via TDM-GCC).
How to check if C++ is installed? 🛠
Open the terminal (or command line) and enter:
g++ --versionIf the compiler is installed, you will see its version.
Key features of C++ 🔧
High performance: C++ is used for programs where speed is important.
Object-orientedness: Allows you to conveniently organize the code.
Direct memory control: In C++, you can manage memory manually.
Multi-paradigm: C++ supports procedural, object-oriented, and functional programming.
C++ Syntax Basics 📚
1. Variables 📦
In C++, variables have a data type that determines what values they can store.
Example of a numeric variable:
int age = 25;Example of a string variable:
#include <iostream>
#include <string>
using namespace std;
int main() {
string name = "Alice";
cout << "Name: " << name << endl;
return 0;
}2. Data output 📤
In C++, data is output using cout.
Example of display:
#include <iostream>
using namespace std;
int main() {
cout << "Hello, world!" << endl;
return 0;
}3. Conditional operators (if...else) 🧐
Using conditions, you can check data and change the behavior of the program.
Example:
#include <iostream>
using namespace std;
int main() {
int age = 20;
if (age >= 18) {
cout << "You're an adult!" << endl;
} else {
cout << "You're still a child." << endl;
}
return 0;
}4. Loops (for) 🔄
Loops allow you to perform the same action multiple times.
Example: output of numbers from 1 to 5
#include <iostream>
using namespace std;
int main() {
for (int i = 1; i <= 5; i++) {
cout << i << endl;
}
return 0;
}5. Functions 📐
Functions allow you to divide the code into logical blocks.
Example of a function for calculating the square of a number:
#include <iostream>
using namespace std;
int square(int x) {
return x * x;
}
int main() {
cout << "Square of the number 5: " << square(5) << endl;
return 0;
}Simple projects in C++ 💡
1. Multiplication table 📊
#include <iostream>
using namespace std;
int main() {
for (int i = 1; i <= 10; i++) {
for (int j = 1; j <= 10; j++) {
cout << i * j << "\\t";
}
cout << endl;
}
return 0;
}2. Calculating the sum of even numbers from 1 to 100 🔢
#include <iostream>
using namespace std;
int main() {
int sum = 0;
for (int i = 2; i <= 100; i += 2) {
sum += i;
}
cout << "The sum of even numbers from 1 to 100: " << sum << endl;
return 0;
}Conclusion 🎉
C++ is a powerful programming language that is great for developing high-performance applications. We have analyzed the basics of C++: variables, input/output, conditions, loops and functions. Now you can write your first programs! 🚀
The more you practice, the better you get. Experiment, write code and master new technologies! Good luck learning C++! 😊
