♦ 🐆 2 min, 🐌 5 min
C++
is definitely one of the most technical language but an extremely powerful tool. So if you're not familiar with any programming language checkout python
first.C
with classes. The official first release of the object-oriented language C++
came out in 1978.An important side note. AT&T Bell Labs is a place that also produced Unix
, C
, transistor and a lot other essential concepts of modern computing. AT&T Bell Labs was an innovation powerhouse that had a massive role in the development of the software world.First, there are more than two versions of C++
. And this is where the mess really begins.C++
was developed as an extension of C
.C++98
We get the famous C++
version 98
. This version gave a bit of a bad rap too C++
because it didn't get any major upgrades for 13 years. Then when updates came, people staid stuck in the past. So if you ever see a really crappy C++
code. It's probably written by a programmer that didn't learn the modern C++
.C++03
minor update of the language but nothing major.C++11
or the modern C++
. Since then C++
is on a three-year release schedule and started to gain all bells and whistles of a modern programming language. A massive enlargement of the standard library: regular expressions, thread support, atomic operations, ... and much more.C++14
generic lambdas, variable templates, ...C++17
filesystem library, type-safe union called variant
, ...C++20
ranges library, ...C++23
experimental and in development.C++
developed massively. So whoever says that the language is dead is wrong. Language is starting to awaken from the dead 🙂C++
python
, C++
is a compiled language (also a complicated language). Once we write our file hello_world.cpp
we need to convert the file into an executable. To do that we use a compiler.Depending on the platform, either gcc
or g++
should be available. But before we dive into the compiler, let's write a simple Hello, world!
example.Hello, world!
in C++
?hello_world.cpp
and place the following into it:#include
int main(){
std::cout << "Hello, world!" << std::endl;
return 0;
}
We'll get into details of what's what in a second. Let's first run the program.C++
program?C++
program into machine-readable code. We do this by using something called a compiler.On macOS
us g++
on linux
use gcc
:> g++ hello_world.cpp
Above will create an executable file called a.out
in the same folder as you ran the script. Now to execute the program run:> ./a.out
Hello, world!
That's it../
in front of a.out
is needed to tell the command line to run the script from the current directory.The extra step is required because with command g++ hello_world.cpp
we first compile the program or convert it into machine-readable code and then with ./a.out
we execute the program.hello_wordl.cpp
#include
int main(){
std::cout << "Hello, world!" << std::endl;
return 0;
}
apart line, by line. First line:#include
is an import statement. We tell C++
to include library iostream
. The library we need to print characters on the screen. Then we have:int main(){
Here we define a function named main()
that doesn't get any input parameters. Its return value is of type int
. The {
curly bracket opens up the scope and }
closes the function's scope. So the whole function is:int main(){
// function body
return 0;
}
{}
bracket as mentioned defines the scope. You can imagine a scope as a box in which variables are global. Once the scope ends the variables and everything that was created inside the scope is deleted. Unless you used pointers in the wrong way, but that's another story.Then we have the print statement:std::cout << "Hello, world!" << std::endl;
The whole thing works much like print()
in python
. The wired symbols and what they mean will be discussed in the future.We'll go further into the details in the next posts. I hope you're not afraid and scared shitless at this point because C++
is a complicated beast. But once you master it, you get access to entirely new computing frontiers that are just a wet dream in terms of performance in other languages.
Get notified & read regularly 👇