Why C++ is a good first language to learn

Jan 22, 2019 - 7 min read
Educative
editor-page-cover

You might think of C++ as an antique programming language, but C++ is still readily used in programming today. Despite the advent of popular object-oriented programming languages like Python, C++ continues to have a dedicated space in the tech world.

C++ is still the go to language for solutions that need fast machine performance. AAA video games, IoT, embedded systems, and resource-heavy VR and AI applications all run on C or C++.

There’s plenty of life in C++ yet. Today, we’ll explore what makes C++ one of the best first languages to learn.

Here’s what we’ll cover today:


Learn C++ for coding interviews

Ace the C++ interview the first time, with hands-on coding practice.

Ace the C++ Coding Interview


Reasons to learn C++ today


1. Learn about computers and compilers

C++ is close to the metal — just a few small steps away from assembly code.

While other programming languages are built around the business domain, C++ is built around the computer. This gives you a much greater understanding of all the building blocks of programming (useful when you’re starting out).

widget

C++ allows you to learn programming from the ground up. You have to explain everything you do, which gives you a deeper understanding of how all the parts work.

A mastery of C++ will familiarize you with:

  • Efficient memory management and pointers — why they’re important and what they do
  • Meta-programming — how a program can examine information about itself
  • Compile time and load time — the difference between them
  • Optimization — what it really means, and how to optimize while you code
  • Dynamic libraries — how they really work, and what to do with them
  • Generic programming — programs evaluated at compile time

2. You’ll pick up other languages faster

Most other major programming languages have syntax based on C++. If you get a good grasp of C++, you’ll be able to pick up other, more verbose languages like Java, far more easily. C++ helps to understand the logic structure of all programming.

It’s actually a lot harder to start with another programming language, and then move to C++. A language like Python, optimized for the way humans think, won’t teach you the way computers think. You may need to re-learn programming from the ground up, if you move to C++.

C++ doesn’t tie you to a specific programming paradigm (like object-oriented programming), so you can easily experiment with different techniques as you learn.


3. Develop hirable skills

With so many developers to choose from, companies are looking for candidates with developed skills like problem-solving, creativity, and determination. C++ teaches you how to be a real, raw problem solver.

One common complaint about learning C++ is that there’s hardly any abstraction in it.

You have to define just about every attribute to make the code work. This can result in more complex, lengthy code to write and dig through, unlike more elegant languages like Python.

There’s no garbage collection — you must explicitly mark objects to be deleted. And memory management is done manually. You are in full control. And when something breaks, it’s on you.

This is where the real programming skill is developed.

Code runs slow?

You’ll need to figure out where the memory is being wasted, and how to dynamically allocate it.

Got a bug?

You’ll need to roll up your sleeves and search your code. An inconvenience for sure, but one that builds character and dev cred.

You’ll learn to adopt a more clear and consistent coding style, comment the code as you write it, and learn to limit the visibility of class internals to the outside world — all important facets of object-oriented programming.


Get started with C++

If you’re new to C++, it can look pretty confusing. Let’s take a quick look at some simple C++ so you can see the general setup of most programs.

#include <iostream> //header file library 
using namespace std; //using standard library

int main() { //main function
  cout << "Hello World \n"; // first object
  cout << "Learn C++ \n\n"; //second object with blank line
  cout << "Educative Team"; //third object 
  return 0; //no other output or return
} //end of code to exectute

#include <iostream> is a header file library. A header file imports features into your program. We’re basically asking that the program copy the content from a file called <iostream>. This stands for input and output stream, and it defines the standards for the objects in our code.

using namespace std means that we are using object and variable names from the standard library (std). This statement is often abbreviated with the keyword std and the operator ::. The int main ( ) is used to specify the main function.

It is a very important part of C++ programs. A function essentially defines an action for your code. Anything within the curly brackets { } will be executed.

cout is an object (pronounced see - out). In this example, it defines our outputs: the strings of words. We write a new object using cout on the second line. The character \n makes the text execute on a different line.

Including two \n\n creates a blank space. By writing return 0, we are telling the program that nothing will return. We are only outputting strings of text. Note that we use the << operator to name our objects. The semi colon ; functions like a period.

Writing and experimenting with simple programs like this is the perfect way to learn C++.

widget

Tips for learning C++

C++ isn’t the easiest programming language to pick up, but you’re well on your way!With the right mindset and tools at your disposal, learning C++ can be fun and enriching for any developer.

Here are some points to keep in mind as you learn:


Be a problem solver

Any beginning coder should have a question they ask themselves any time they encounter a new syntax feature to learn:

“What problem does this solve?”

All programming is made to solve problems. By focusing on what problem you are solving with each new thing you learn, you’ll get a much deeper understanding of the language and programming in general.


Learn from others

Thankfully, you’re not the first to learn C++. If you’re struggling with an issue, try searching on forums like StackOverflow.

You’re probably not the only one having the problem! C++ has a thriving community of developers that have been where you are and want to help.


Get acquainted with the latest version of C++

C++17 is the most recent version of C++, but it’s an incremental update from C++11, the last major upgrade.

You’ll definitely want to start there. There are many new features designed to make C++ easier for beginners to pick up, and lots of ways to make your code shorter and easier to read.

Practicing the newest features will ensure you’re not spending time on phased out problems.


Next steps

If you want to pick up C++, you can have to work with code hands-on. Apply concepts as you learn them helps to cement learning so you can apply it later. Live practice also allows you to move at your own pace.

Educative’s new interactive course, Learn C++ from Scratch, is the perfect primer to learning C++ from scratch. You’ll start with a simple Hello, World! program, explore the basic concepts (conditional statements, loop statements, functions), then learn to use classes and templates to write better, modular code.

By the end, you’ll have the practiced C++ skills you need to build your own complex solutions.

Happy learning!


WRITTEN BYEducative

Join a community of 500,000 monthly readers. A free, bi-monthly email with a roundup of Educative's top articles and coding tips.