how long does it take to learn c++ - is c++ hard to learn

How Long Does It Take To Learn C++?

From browsers to gaming and robotics, C++ is the programmer’s go-to language. But if you’re  curious about learning the language, you’ve likely already heard that C++ is hard to learn. In this article, we’ll provide our thoughts on how long it really takes to learn C++,  and why you’ll benefit from giving it a try.

What Is C++?

C++ descended from the C language, an iconic low-level programming language that has found many different uses. For example, both the Linux kernel and the entire Python language were written in C. The term “low-level” refers to a language’s relative proximity to the computer’s hardware. The more a language abstracts away from assembly code, the more high-level it’s considered. 

Bjarne Stroustrup began working on C++ back in 1979. Then called “C with Classes,” it aimed to combine C’s low-level features with a high-level object-oriented paradigm. The successor of “C with Classes” was named C++, referencing the incremental operator found in both languages (++ means “add one to the value at hand”).

Since then, C++ has evolved into a key language for applications that rely on superfast processing power, such as video games, autonomous driving and the Internet of Things (IoT). The TIOBE index ranked it as the fourth most popular programming language in 2020.

C++ is a compiled language. This means that upon writing the program and storing it in a script, we call a compiler that converts the entire program into machine-readable code. Compared to interpreted languages like JavaScript and Python, compiled languages execute much faster. 

Is C++ Hard To Learn?

So how hard is it to learn C++, really? Of course, there’s not a universal answer. How long it would take you would depend on many factors, such as your background and motivation, and what you want to do with the language. In other words, we can approach learning to program in the same way as we would go about learning to speak a new language.

That being said, it’s true that many people personally find C++ to be harder than other languages. In some cases this is simply due to the programming paradigm: High-level languages such as Python and Java are “easier” by definition, as they hide much of the complexity from the user. On the flipside, this makes them less flexible than low-level languages. 

Coding in a high-level language is a bit like living in a house with many domestic workers. You might have a nanny, a cleaning person and a gardener. Consequently, you think less about everyday problems and can dedicate all your time to your job and hobbies. It’s only when things stop working that you realize how much you rely on your employees. With a low-level language, you do your own cleaning, gardening and child-rearing.

While C++ does have low-level features akin to C, it also supports object-oriented programming, and thus adheres to the high-level paradigm. Fittingly, C++ is sometimes referred to as a mid-level language. Its hybrid nature accounts both for C++’s strengths, as well as its challenges.

There’s a rumor floating around the internet that Bjarne himself rates his own C++ proficiency a seven out of 10. Whether that’s true or not, it shows the extent to which C++ programmers themselves struggle with the language’s complexity. Take a look at Bjarne’s FAQ where he answers questions such as “How long does it take to learn C++?” and “What’s so great about classes?”

C++’s syntax itself isn’t hard to learn, especially if you already know C. However, the versatility that makes C++ such a powerful and interesting language is itself the reason why many people find it hard. Let’s look at some sources of confusion that may arise when you begin to learn C++.

Memory Management

Whenever you create a new data structure (e.g., an integer, string or array), it has to be physically allocated to an address in memory. In high-level languages, this is something we rarely think about — the memory manager does it all for us! But in C++, we have to think about our hardware resources and how to most efficiently use them. So after creating a variable and assigning it a place in memory, we have to actively de-assign that space when we stop using the variable.

You can probably think of many ways in which this can go wrong. For instance, if we want to use a variable that has been deallocated, the object would no longer exist. There’s also the reverse case of a variable continuing to occupy space although it’s no longer needed by the program. This is referred to as a memory leak. When a program with a memory leak continues to run for a while, amassing more and more unneeded variables, this can result in a crash.

Pointers

This topic seems to be a source of confusion for many C++ newbies. Pointers are simply variables that contain the addresses of other variables. Their big advantage is that you can operate with a pointer (your variable’s address) without invoking the variable itself. This makes for faster, more efficient code. And since C++ is all about efficiency, pointers are used quite a lot in C++ programs. Handling pointers in the wrong way can again lead to memory issues — imagine knowing the pointer but forgetting the variable, or the other way round.

Classes

As C++’s former name clearly stresses, the whole point of this new language was to have “C with classes.” If you come from another object-oriented language, you’ll have no problem understanding the concept. 

Classes are blueprints for complex data types known as objects. They come with all kinds of attributes and functions. Whenever you instantiate a class, you create a new object that comes ready with all the functionality. Classes make for great, modular code.

Compiling

We’ve already mentioned the compiler. A compiler is like a translator that converts an entire script to a language that the computer understands (ones and zeros, essentially). There are many different compilers and you’ll have to choose yours according to your operating system. If you decide to write C++ code in an interactive development environment (IDE) such as Visual Studio or Eclipse, it will already include a C++ compiler.

Typing

If you’re coming from a dynamically typed language like Python, you might not be familiar with this concept. Languages like C and C++ are strongly typed, meaning that when you create a new variable, you declare its type — whether a vector, a floating-point number or a character — and it cannot be anything else. Python, in comparison, uses duck-typing, by which types are declared implicitly and can be changed any time.

Strongly typed code has the great advantage of being somewhat self-documenting. Whereas in Python you often need to write a docstring detailing what types of arguments your function accepts and what it returns, in C++ all this information is conveyed in the function itself.  

Why You Should Learn C++

As general advice, learning a new programming language — especially one that operates with paradigms that are new to you — is never a bad idea. That’s because good programming is not really about knowing a particular language inside out. 

Rather, it’s knowing how to write clean, documented code to achieve what you want. This skill is better honed by learning more about programming in general rather than by mastering every aspect of a given language.

But if you’re looking to get into one of the areas we’ve mentioned (i.e., gaming, self-driving cars, IoT or even banking), developing a solid base in C++ will pay dividends

The Next Step

So how long does it take to learn C++? That depends on the student, of course. 
You might find frustration along your C++ learning journey as you start grappling with topics like memory management and classes. Consider a structured learning approach to stay motivated and speed the process along.

To get started, check out our C++ Nanodegree.

Start Learning