0.2 — Introduction to programming languages

Modern computers are incredibly fast, and getting faster all the time. Yet with this speed comes some significant constraints. Computers only natively understand a very limited set of instructions, and must be told exactly what to do. A program (also commonly called an application or software) is a set of instructions that tells the computer what to do. The physical computer machinery that executes the instructions is the hardware.

Machine Language

A computer’s CPU is incapable of speaking C++. The very limited set of instructions that a CPU natively understands is called machine code (or machine language or an instruction set). How these instructions are organized is beyond the scope of this introduction, but it is interesting to note two things. First, each instruction is composed of a number of binary digits, each of which can only be a 0 or a 1. These binary numbers are often called bits (short for binary digit). For example, the MIPS architecture instruction set always has instructions that are 32 bits long. Other architectures (such as the x86, which you are likely using) have instructions that can be a variable length.

Here is an example x86 machine language instruction: 10110000 01100001

Second, each set of binary digits is translated by the CPU into an instruction that tells it to do a very specific job, such as compare these two numbers, or put this number in that memory location. Different types of CPUs will typically have different instruction sets, so instructions that would run on a Pentium 4 would not run on a Macintosh PowerPC based computer. Back when computers were first invented, programmers had to write programs directly in machine language, which was a very difficult and time consuming thing to do.

Assembly Language

Because machine language is so hard to program with, assembly language was invented. In an assembly language, each instruction is identified by a short name (rather than a set of bits), and variables can be identified by names rather than numbers. This makes them much easier to read and write. However, the CPU can not understand assembly language directly. Instead, it must be translated into machine language by using an assembler. Assembly languages tend to be very fast, and assembly is still used today when speed is critical. However, the reason assembly language is so fast is because assembly language is tailored to a particular CPU. Assembly programs written for one CPU will not run on another CPU. Furthermore, assembly languages still require a lot of instructions to do even simple tasks, and are not very human readable.

Here is the same instruction as above in assembly language: mov al, 061h

High-level Languages

To address these concerns, high-level programming languages were developed. C, C++, Pascal, Java, Javascript, and Perl, are all high level languages. High level languages allow the programmer to write programs without having to be as concerned about what kind of computer the program is being run on. Programs written in high level languages must be translated into a form that the CPU can understand before they can be executed. There are two primary ways this is done: compiling and interpreting.

A compiler is a program that reads code and produces a stand-alone executable program that the CPU can understand directly. Once your code has been turned into an executable, you do not need the compiler to run the program. Although it may intuitively seem like high-level languages would be significantly less efficient than assembly languages, modern compilers do an excellent job of converting high-level languages into fast executables. Sometimes, they even do a better job than human coders can do in assembly language!

Here is a simplified representation of the compiling process:
Example of compiling

An interpreter is a program that directly executes your code without compiling it into machine code first. Interpreters tend to be more flexible, but are less efficient when running programs because the interpreting process needs to be done every time the program is run. This means the interpreter is needed every time the program is run.

Here is a simplified representation of the interpretation process:
Example of interpreting

Any language can be compiled or interpreted, however, traditionally languages like C, C++, and Pascal are typically compiled, whereas “scripting” languages like Perl and Javascript are interpreted. Some languages, like Java, use a mix of the two.

High level languages have several desirable properties.

First, high level languages are much easier to read and write.

Here is the same instruction as above in C/C++: a = 97;

Second, they require less instructions to perform the same task as lower level languages. In C++ you can do something like a = b * 2 + 5; in one line. In assembly language, this would take 5 or 6 different instructions.

Third, you don’t have to concern yourself with details such as loading variables into CPU registers. The compiler or interpreter takes care of all those details for you.

And fourth, they are portable to different architectures, with one major exception, which we will discuss in a moment.

Example of portability

The exception to portability is that many platforms, such as Microsoft Windows, contain platform-specific functions that you can use in your code. These can make it much easier to write a program for a specific platform, but at the expense of portability. In these tutorials, we will explicitly point out whenever we show you anything that is platform specific.

0.3 -- Introduction to C/C++
0.1 -- Introduction to these tutorials

177 comments to 0.2 — Introduction to programming languages

  • Roly Glez

    Hey, I'm using this to review Cpp from my computer engineering bachelors. Thanks for this guide!

  • Kyaw Zin Thet

    Hi Sir Alex,

    I just want to say thank you so much for your effort and time to support all of us.
    I really like your explanation and tutorials.

  • Rick

    Hello Alex, I'm a Jamaican and is trying to be a self taught programmer until i can afford to attend an institution. As far as i can see this tutorial is great so far, I've tried video tutorial but got to a point and stopped. So what i want to say is great job and keep it up.
    ps. Can i get your email address.

  • Jack Bing

    From what I gather, the compiler essentially creates code that is executable as per that systems CPU architecture. Also, platform specific functions in code can only be used on that particular platform, and the compiler and CPU architecture have only support of the platform to do with it. But suppose, two different computer architectures of CPU's could host the same platform, then would the two different compilers for the two different systems both allow for the functions ? Is it even possible for two architectures to host the same platform ? Correct me if I have got something fundamentally wrong.

    • Alex

      Linux is a good example of a platform that's been ported to different architectures (see Generally, executables only support the OS and architecture they were built for. You can read more here:

  • What do you mean. A = 97

    What interpetation would be applied?
    Is that equal to binary and assembly, examples on page.
    Where is the language generated?

  • Rafael A. A. Merlo

    Hey Alex =)

    Really, thank you very much for all the time, effort and love you put in providing all this great educational material for free for us. You are awsome!

    Me and a friend have decided yesterday to follow your material from zero to end. My personal goal for this is to take a Open Source music notation software, MuseScore (which is written in C++ and Qt), and write a big scope plugin for it that transforms and add to it a interface to write dance notation.

    Probably I'll need to find another site to learn the Qt programming language, but for the little I unterstood from it seems it was build over the C++, am I right?

    Well, wish us luck 😀
    Hugs from Brazil o/

    • Alex

      Yep. Qt has a few extra things you'll want to learn about (e.g. how the slots and signals system works, and how to instantiate windows), but once you know the basics of C++ this should all be doable.

  • Duy

    I just find out this website, I think it is great to learn c++.

  • James

    I just found this site today, I'm really excited to begin learning one of the most popular and useful high-level programming languages out there today.  Although I'm nearly 33 years old, it's not too late to get into such an amazing and profitable new skillset.  Good luck to everyone on their own adventure.

  • ayush singh

    which programming language is best for begginers other than c++ if i am a school grade student

  • Am I correct to think that the assembly instruction (for reference, this was

    ) instructs the processor to "move into the al register the hexadecimal value 061"? I mean I might as well learn a little "bit" (pardon  the pun) of x86 assembly while I'm here 🙂

  • Elton Ngugi

    this is the best site to learn any programing language.The explanation is very detailed and leaves one with complete understanding. I highly recommend everyone to visit and use this site for individual benefits.
    Thank you

  • Denise

    Great tutorial..!

  • Isabel

    Hi Alex! Thank you for sharing your knowledge! you have my respect! I think I'm kind of confused with some information. I don't think I have very clear the difference between an assembler and a compiler, and the other things I cannot figure them out, are these three concepts: x86 compiler, PowerPC, MIPS. Finally, another concept that I don't completely understand, is the computer architecture. Thank you Alex you awesome!

    • Alex

      And assembler is used for compiling assembly code into an executable that can be run. A compiler is used for compiling a high-level language into an executable that can be run.
      x86, PowerPC, and MIPS are all different computer architectures. They have different instruction sets, different strengths and weaknesses, and different assembly language. But they can all compile the same C/C++ code.
      For more info on computer architectures, see

  • Hi Alex,

    Your tutorials are really very helpful to learn C++ easily. I've already started to learn and have determined to finish it. Why I would be failed to cover the whole ready made amazing lessons while the master of C++ (Alex) have already been covered up all the lessons with good explanation for learning?

    Thanks a lot sir.

  • Ganesh Bhadane

    Hi Alex,
    I have simple question. What is compile time and runtime??

  • nida

    I have no knowledge about any basics to programming. Can i complete this course?

  • Abhishek Raina

    Hello teacher,
    First of all thank you for posting this and helping all of us!
    So I have been learning java (on blueJ) for a few years and it will continue for a few more years. My problem is will learning C++ make it difficult for me to understand java? I was scrolling down the index of learncpp and most of the topics looked familiar. Is C++ similar to java or is it very different? I really wanted to learn C++ but I could not let it hinder my progress in java.
    What do you suggest?

  • Xrem

    The material in this site is so clear and straight-forward. I will try to click every add on the pages. Thank you sooooooooo much.

  • Therese McLeod

    #include <iostream>
    using namespace std;
    void doPrint()
        cout << "In doPrint()" << endl;

    int main()
        cout << "Starting Main()" << endl;
        cout << "Ending Main()" << endl;
        return 0;
    Yay, it was broken, now it's fixed, the solution was strange, languages betwixt.

  • disha

    Hi Alex,

    Thanx aloooooott for such a beautiful website.. no words to explain how useful it is..

    I've a que that:

    I've done my bachelors degree in computers..

    if I'm learning c++ from here in a best way then of course there is no need for a classes but I wanna get certified in c++ then how will i get a certification for the same???

    I need a certification which is acceptable for all the well known companies..

    Is there any way that we can directly apply for a certification and get it.. if yes then where and how can we apply and how much expenses will it take??

    do rply plzz.. it's really very important for me...

    and thanks in advance..

    • Alex

      There are a few companies that offer certifications in C++. Microsoft is probably the best known of the bunch. However, certifications don't tend to be very highly regarded in programming, so I'm not sure that's a worthwhile course of action.

  • Ben

    In what way can I support this noble effort, Alex? I am studying Cloud Computing and knowledge of C++ is required.

  • Lizzy

    Does learncpp have any connection to codecademy? Because this comment is using my codecademy profile pic.

    • Alex

      This site has no association with codeacademy. However, if you comment and use an email address that has an associated gravatar, we'll pull it in the gravatar and display it. Look up gravatar for more information on what it is.

  • GEScott71

    This sounds great so far - thanks for the great intro.  I am going to work through this entire tutorial, and will comment after each section as to how I am doing (and likely with many questions!).

    I found many of the comments above motivating, so I'll add a few details about myself and motivation here.

    I am a 45yo product manager of embedded systems for railroad locomotives, working for General Electric.  I am a mechanical engineer by education.  I haven't done any programming since BASIC in junior high and 1 semester of FORTRAN in college.  I want to learn to code for 2 reasons:  1)GE is working to become a software company and I want to better understand how software is created and implemented to do my job better, and 2)There are some small personal projects I want to develop my own programs for, as I haven't found pre-built solutions.

    Thanks Alex!

  • Clark

    Great site, I'm so happy that I found it, keep up the good work, cheers mate !

  • dontletmegetme

    I love this website

  • UKImperium

    Easy to read & learn. It's great, not like most sites you visit where they bored you on the first sentence.

Leave a Comment

Put all code inside code tags: [code]your code here[/code]