A Beginner's Introduction to C++

The first in the series.


C++ is a statically typed, compiled language that has been there for ages. That’s about what you need to know to understand this tutorial. I will assume that know nothing more than this. If you don’t even know this, well, lemme start with that.

What is Statically Typed?

Well, if you have ever written a basic C or C++ program, you would know that we define the type of variables. You know, we kinda need to say that “obviousNumber” is an actual number, and you want to keep the code simple, so you use code like this:int obviousNumber;

So you say to the C++ compiler (more on that later), that this variable, obviousNumber, is a number. In languages that aren’t statically typed, or rather, dynamically typed, the langauge guesses the type of the variable.

What Is A Compiler?

The compiler is a piece of software that changes your human-readable code, which looks like this:

#include <iostream>
using namespace std;
int main()
  cout<<"Hello, World!";

into this:

0x0000000000400776 <+0>:	push   %rbp
0x0000000000400777 <+1>:	mov    %rsp,%rbp
0x000000000040077a <+4>:	mov    $0x400874,%esi
0x000000000040077f <+9>:	mov    $0x601060,%edi
0x0000000000400784 <+14>:	callq  0x400660
0x0000000000400789 <+19>:	mov    $0x0,%eax
0x000000000040078e <+24>:	pop    %rbp
0x000000000040078f <+25>:	retq

This right here, is called Assembly. This is the closest we can get to machine code without actually writing zeroes and ones. (And I will hopefully make a tutorial on this)

The Most Basic Program in C++

The program that was shown earlier in this post was the “Hello World” program. I will assume that the people reading this don’t really know it in this way. Instead, most people my age would probably write this:

#include <iostream.h>
void main()
	cout<<"Hello World!";

I don’t blame them for writing it in this way. Heck, I too was taught that this is the Hello World program written in C++. Not quite. There’s actually a difference between the C++ taught in schools in India and the one used in the field. Schools normally use it because it is easier to comprehend. I will use both codes in my tutorials, becuase I’ll mostly just be using them to teach specific concepts in the C++ language.

The next tutorial will probably come next week, and it’ll be much bigger than this one.