kids encyclopedia robot

C++ facts for kids

Kids Encyclopedia Facts


Quick facts for kids
C++
ISO C++ Logo.svg
Logo endorsed by the C++ standards committee
Paradigms Multi-paradigm: procedural, imperative, functional, object-oriented, generic, modular
Family C
Designed by Bjarne Stroustrup
Developer ISO/IEC JTC 1 (Joint Technical Committee 1) / SC 22 (Subcommittee 22) / WG 21 (Working Group 21)
First appeared 1985; 40 years ago (1985)
Stable release
C++23 (ISO/IEC 14882:2024) / 19 October 2024; 9 months ago (2024-10-19)
Preview release
C++26 / 16 October 2024; 9 months ago (2024-10-16)
Typing discipline Static, strong, nominative, partially inferred
OS Cross-platform
Filename extensions .C, .cc, .cpp, .cxx, .c++, .h, .H, .hh, .hpp, .hxx, .h++ .cppm, .ixx
Major implementations
GCC, LLVM Clang, Microsoft Visual C++, Embarcadero C++Builder, Intel C++ Compiler, IBM XL C++, EDG
Influenced by
Ada, ALGOL 68, BCPL, C, CLU, F#, ML, Mesa, Modula-2, Simula, Smalltalk
Influenced
Ada 95, C#, C99, Carbon, Chapel, Clojure, D, Java, JS++, Lua, Nim, Objective-C++, Perl, PHP, Python, Rust, Seed7

C++ (pronounced "C plus plus") is a powerful programming language used to create many different kinds of computer programs. It was invented by a Danish computer scientist named Bjarne Stroustrup.

C++ was first released in 1985. It started as an improved version of the C programming language. C++ added new features, especially "object-oriented programming" (OOP). This helps programmers organize their code better.

Over time, C++ has grown a lot. It now includes features for working with computer memory directly. This makes it great for building operating systems like Linux or Windows. It's also used for video games and other programs that need to run very fast. C++ programs are usually turned into computer code by a special program called a compiler.

C++ is designed to be fast, efficient, and flexible. It's used for many things, including:

  • Desktop applications (like the programs you use on your computer)
  • Video games
  • Servers (computers that store information for websites or online games)
  • Programs that need to perform very quickly, like those in space probes.

The way C++ works is set by an international group called the International Organization for Standardization (ISO). The newest official version of C++ was released in October 2024. It's known as C++23.

History of C++

BjarneStroustrup
Bjarne Stroustrup, the creator of C++, in his AT&T New Jersey office, c. 2000

The story of C++ began in 1979. A computer scientist named Bjarne Stroustrup started working on a language he called "C with Classes." He wanted to create a language that was both fast and easy to organize for big projects.

Stroustrup had used two other programming languages before. One was Simula, which was great for organizing code but too slow. The other was BCPL, which was fast but hard to use for large programs. He decided to add the good features of Simula to the C language. C was chosen because it was already popular, fast, and could work on many different computers.

In 1982, Stroustrup decided to rename "C with Classes" to "C++." The "++" comes from a common symbol in C. It means "add one to something." So, C++ means "C, but better!"

New features were added to C++ over time. These included things like virtual functions and ways to make functions and operators work differently depending on what they were used with. A new compiler, called Cfront, was also developed just for C++.

In 1985, the first book about C++ was published. It became the main guide for people learning the language. The first commercial version of C++ was also released that year.

20160121 CppFRUG Joel Falcou CppQuiz 3
A quiz on C++11 features being given in Paris in 2015

C++ continued to grow. In 1989, C++ 2.0 came out with more new features. These included ways to inherit features from multiple sources and special functions for classes.

In 1998, C++ became an official standard language. This meant that everyone agreed on how C++ should work. A small update, called C++03, followed in 2003.

After that, C++ evolved more slowly until 2011. That year, the C++11 standard was released. It added many new and exciting features. Smaller updates, C++14 and C++17, came out in 2014 and 2017. The C++20 standard was approved in 2020. The most recent standard, C++23, was published in October 2024.

In December 2022, C++ became one of the top programming languages. It was ranked third on the TIOBE index, which measures language popularity. As of November 2024, it ranks second, right after Python.

Why the Name C++?

The name "C++" shows that the language is an improved version of C. The "++" symbol is an operator in C that increases a variable's value by one. It's like saying "C, plus one more feature!"

Before it was called C++, people sometimes called it "new C" or "C with Classes." The name C++ was first used in December 1983.

What C++ is Built On

C++ was created with some important ideas in mind:

  • It should solve real-world problems and be useful right away.
  • Every feature should be possible to build.
  • Programmers should be able to choose their own style of coding.
  • It's better to allow a useful feature, even if it could be misused sometimes.
  • Programs should be easy to organize into different parts.
  • It should not secretly break the rules of how data types work.
  • Types created by programmers should work just as well as built-in types.
  • Features you don't use should not slow down your program.
  • C++ should work well with other programming languages.
  • If a programmer's goal isn't clear, C++ should let them control things manually.

How C++ is Standardized

C++ standards
Year Standard Name Informal Name
1998 14882:1998 C++98
2003 14882:2003 C++03
2011 14882:2011 C++11
2014 14882:2014 C++14
2017 14882:2017 C++17
2020 14882:2020 C++20
2024 14882:2024 C++23
scope="row" 0TBA C++26

C++ is made official by a group within the ISO. This group is called JTC1/SC22/WG21. They have released several versions of the C++ standard. They are currently working on the next version, C++26.

C++ Standards Committee meeting - July 1996 Stockholm - Wednesday general session
A meeting of the C++ standards committee in Stockholm in 1996

The first official C++ standard, C++98, came out in 1998. In 2003, a new version, C++03, was published to fix some issues.

The next big update was C++11, released in 2011. It added many new features to the language and its standard library. After that, C++14 came out in 2014, mostly with bug fixes and small improvements.

Then came C++17 in 2017, which was another major update. The C++20 standard was approved in 2020. The most recent standard, C++23, was published in October 2024.

How C++ Works

C++ has two main parts. One part lets you work directly with the computer's hardware, like the C language does. The other part helps you create "abstractions." These are like building blocks that make complex tasks simpler. C++ lets you do both efficiently.

C++ uses most of the same rules for writing code as C. This means a simple "hello world" program written in C will also work in C++. Here's an example of a "hello world" program in C++:

#include <iostream>

int main()
{
    std::cout << "Hello, world!\n";
}

This code tells the computer to print "Hello, world!" on the screen.

C++ Standard Library

ANSI ISO C++ WP
The draft "Working Paper" standard that became approved as C++98; half of its size was devoted to the C++ Standard Library.

The C++ standard includes not just the language rules but also a "standard library." This library is a collection of ready-to-use tools and functions. Programmers expect these tools to be available with every major C++ setup.

The standard library includes:

  • Containers: Ways to store collections of items, like vectors (lists that can grow) and maps (like dictionaries).
  • Algorithms: Functions to do common tasks, such as finding items, sorting lists, or searching.
  • Input/Output: Tools for reading information from the keyboard or files and writing information to the screen or files.
  • Smart Pointers: Tools that help manage computer memory automatically.
  • Multithreading: Features for programs that need to do many things at once.

A big part of the C++ library is based on something called the Standard Template Library (STL). The STL provides useful tools like:

  • Containers: Such as vectors and lists to hold objects.
  • Iterators: Tools that help you go through items in containers, similar to how you access items in an array.
  • Algorithms: Functions that perform actions like searching and sorting on the items in your containers.

You can use these library features by including a "standard header" in your code. For example, to use input/output, you might write `#include <iostream>`. With newer versions of C++, you can also use "modules" to import the library, like `import std;`.

Most C++ compilers provide a version of the C++ standard library that follows the official rules.

C++ Core Guidelines

The C++ Core Guidelines are a set of rules and best practices. They were created by Bjarne Stroustrup (the inventor of C++) and Herb Sutter (who leads the C++ ISO Working Group). These guidelines help programmers write better, safer, and more efficient C++ code, especially with newer versions of the language.

The main goal is to help programmers write code that is safe with data types and computer resources. These guidelines were announced in 2015. There's also a special library, the Guideline Support Library (GSL), that helps programmers follow these rules.

Compatibility

C++ compilers are made by different companies. Because of this, programs made by one compiler might not work perfectly with parts made by another. However, there are efforts to make them more compatible, especially for specific computer systems.

Working with C

C++ is often seen as an improved version of the C language. Most C code can be made to work in C++. However, there are a few small differences. For example, C++ is stricter about how you use certain types of pointers to keep your code safer. Also, C++ has new keywords that might have been used as variable names in older C programs.

Newer versions of the C standard, like C99, have added some features that C++ already had, such as comments that start with `//`. However, C99 also added some features that C++ doesn't support in the same way.

To use C and C++ code together, you often need to tell the C++ compiler that some functions are from C. You do this by putting them inside an `extern "C" {/*...*/}` block.

Using Assembly Language

Programmers sometimes use assembly language with C++ code. Assembly language is a very low-level language that gives programmers direct control over the computer's hardware. This can make programs run faster or give more precise control.

C++ allows you to embed assembly language directly into your code. This is called "inline assembly." However, how you write inline assembly can be different depending on which C++ compiler you use.

For example, compilers like GCC and Clang use a specific way to write inline assembly. Microsoft Visual C++ (MSVC) used to have its own way, but it has changed for newer 64-bit programs.

To make C++ and assembly code work together:

  • If you call an assembly function from C++, you use `extern "C"` to prevent C++ from changing the function's name.
  • If you have global variables in assembly, you declare them as `extern` in C++ and mark them as global in assembly.
  • You can embed assembly directly in C++ using the `asm` keyword.

Here's a simple example of inline assembly in C++ (for GCC/Clang compilers):

//main.cpp (using GCC/CLANG compiler)
import std;

int main() {
    int x = 10, y = 20, sum;

    asm volatile (
        "add %0, %1, %2"
        : "=r" (sum)   // Output: sum will store the result
        : "r" (x), "r" (y) // Inputs: x and y are used
    );

    std::println("Sum using inline ASM: {}", sum);
    return 0;
}

This code uses a very simple assembly instruction to add two numbers.

See also

Kids robot.svg In Spanish: C++ para niños

  • Carbon (programming language)
  • Comparison of programming languages
  • List of C++ compilers
  • Outline of C++
  • Category:C++ libraries
kids search engine
C++ Facts for Kids. Kiddle Encyclopedia.