What is: C++?

by Paul

C++ is an all-purpose programming language which is based upon one of the most used programming languages ever - C.

C++ first appeared in 1983, ten years after the programming language C was first completed. The name C++ is a pun involving the increment operator (++) which is used fairly frequently in C and when used, it increases the value of the operand by 1.

The main reason C++ was created was to include object-oriented features into the programming language C. Being object-oriented allows programmers to model programs around the idea of "objects" - essentially a box which holds both data and instructions.

A small and simple C++ program
A small and simple C++ program

What does C++ look like?

Unlike HTML or CSS, C++ is a programming language. This means that for the most part, we are limited by our imagination as to what we can achieve with it.

As it is a very powerful tool, it certainly isn't as easy to pick up as HTML or CSS, but this shouldn't deter you if you wish to learn C++.

You'll notice semi-colons peppered throughout the code above. These are the bane of most programmers' existence but at the same time are extremely important to the program.

Why? Well, each semi-colon tells the compiler that this line of code has finished and that it should move onto the next one.

But what's a compiler? Unfortunately, computers don't understand English. If they did, a lot of programmers would be out of a job and we'd probably have a Skynet type situation on our hands, but since they don't, we need something to translate.

This is what a compiler does. It takes the source code (the code you write) and translates it into something the computer will understand. Doing this allows us to write programs that we can execute and make the computer do things for us.

Another simple program

As with most programming languages, a fundamental part of C++ is variables. You can think of variables as a box with a label attached to it. We can tell the computer to store values in these boxes and store them in the computer's memory (you could think of it like a shelf).

However, we couldn't fit a shoe in a ring box and for similar reasons, there are different types of variables to store different types of data.

When we tell the computer to create a variable, we must also tell it what type of data we will be wanting to put in it. For example, if we wanted to store say, an integer (any whole number), we would have to use a different type of variable than if we wanted to store a string (a series of characters).

Code is typically split up into functions which are a programmer's way of splitting up a large problem into smaller, easier to manage problems. The programmer will then link the functions together and produce a complete solution to the original problem.

There are also hundreds of other different features a programmer can use to make their life easier. Most of these are based upon the fact that they are conditional and so the computer will only use them if a condition is met.

C++ is no different when it comes to learning, there are excellent books available to purchase!

C++ Programming Language, The

View on Amazon

C++ Primer (5th Edition)

View on Amazon

C++ Crash Course: A Fast-Paced Introduction

View on Amazon

Hello, Wizzley!

A program that displays "Hello, Wizzley!"
A program that displays "Hello, Wizzley!"

Traditionally, the program used to illustrate the basic layout of a programming language is to display "Hello, world". Naturally, I've slightly modified this, but the principle is exactly the same.

Lines 1 and 3 are slightly too complex to explain in detail for a beginner's article, but the idea behind them is that they are a link to separate files which contain code themselves.

The two lines are used as a way of putting all of the code contained inside the files into our programme without forcing us to write it out every single time. These lines will need to be present in most basic programs.

Remember functions? Line 5 contains the function "main". You can tell it's a function because it has "()" after it. There are two types of functions - ones that return (give us something back after the computer has finished executing it) a value and ones that don't.

In this case, main() does return a value. We can tell what kind of value to expect due to the word before the function. Here, it's "int" which stands for "integer". This means that the function "main" will return an integer.

Lines 6 and 9 contain curly brackets. These are used to show where the code in a function starts and stops. Main()'s code starts at line 6 and ends at line 9.

Line 7 is where the magic happens. "cout" which is pronounced "see out" is what we use when we want to make something appear on the screen.

The operator "<<" is used here to tell the computer that we're about to tell it what we want to display on the screen. Following this we can see "Hello, Wizzley!" The computer will display everything between " and ". Now we must use a semi-colon to tell the compiler that this line of code has ended.

Finally, since the function main() needs to return a value, we tell the computer to return 0 (which equates to nothing). Again, we must not forget the semi-colon!

 

The result of the Hello, Wizzley! program
The result of the Hello, Wizzley! program

Programming related t-shirts!

Purchase this t-shirt to tell that special someone they had you at "Hello, world"!

How do I begin to write C++ programs?

C++ certainly isn't the easiest programming language to start learning with, but this doesn't mean that it shouldn't be done.

I find that Microsoft's Visual Express 2010 is great for beginners to use (although remember to select the C++ option when it asks which settings you'd like to use). It's free and fairly clear to see and understand what's going on.

Again, C++ can be a very powerful programming language and as cliché as it sounds, you really are mostly limited by your imagination!

Updated: 12/31/2012, Paul
 
Thank you! Would you like to post a comment now?
16

Comments

Only logged-in users are allowed to comment. Login
Paul on 12/05/2012

I thought it was pretty amazing, never seen it before!

Mira on 12/05/2012

I had to laugh seeing that T-shirt, "You had me at hello world." :D

Paul on 11/13/2012

Certainly one of the go-to languages for almost anything - incredibly useful!

JoHarrington on 11/13/2012

Another great tutorial! I've never learned C++, but this has made me want to tip my toe in this particular cyber water.

You might also like

What is: CSS?

While HTML provides the backbone of a website, CSS allows you to have total c...

What is: HTML?

HTML is the main markup language used to create and display information withi...


Disclosure: This page generates income for authors based on affiliate relationships with our partners, including Amazon, Google and others.
Loading ...
Error!