Languages Features Creators CSV Resources Challenges Add Language
GitHub icon


C++ - Programming language

< >

C++ is a programming language created in 1985 by Bjarne Stroustrup.

#7on PLDB 38Years Old 4.1mUsers
128Books 6Papers 2mRepos

Try now: Riju · Replit

C++ ( pronounced cee plus plus) is a general-purpose programming language. It has imperative, object-oriented and generic programming features, while also providing facilities for low-level memory manipulation. It was designed with a bias toward system programming and embedded, resource-constrained and large systems, with performance, efficiency and flexibility of use as its design highlights. Read more on Wikipedia...

Example from Compiler Explorer:
// Type your code here, or load an example. int square(int num) { return num * num; }
Example from Riju:
#include <iostream> int main() { std::cout << "Hello, world!" << std::endl; return 0; }
Example from hello-world:
#include <iostream> int main() { std::cout << "Hello World" << std::endl; }
// Hello World in C++ (pre-ISO) #include <iostream.h> main() { cout << "Hello World!" << endl; return 0; }
Example from Linguist:
#include <cstdint> namespace Gui { }
Example from Wikipedia:
1 #include <iostream> 2 #include <vector> 3 #include <stdexcept> 4 5 int main() { 6 try { 7 std::vector<int> vec{3, 4, 3, 1}; 8 int i{}; // Throws an exception, std::out_of_range (indexing for vec is from 0-3 not 1-4) 9 } 10 // An exception handler, catches std::out_of_range, which is thrown by 11 catch (std::out_of_range &e) { 12 std::cerr << "Accessing a non-existent element: " << e.what() << '\n'; 13 } 14 // To catch any other standard library exceptions (they derive from std::exception) 15 catch (std::exception &e) { 16 std::cerr << "Exception thrown: " << e.what() << '\n'; 17 } 18 // Catch any unrecognised exceptions (i.e. those which don't derive from std::exception) 19 catch (...) { 20 std::cerr << "Some fatal error\n"; 21 } 22 }

Keywords in C++

#define #defined #elif #else #endif #error #if #ifdef #ifndef #include #line #pragma #undef alignas alignof and andeq asm atomiccancel atomiccommit atomicnoexcept auto bitand bitor bool break case catch char char16t char32t class compl concept const constexpr constcast continue decltype default delete do double dynamiccast else enum explicit export extern false final float for friend goto if inline int import long module mutable namespace new noexcept not noteq nullptr operator or oreq override private protected public register reinterpretcast requires return short signed sizeof static staticassert staticcast struct switch synchronized template this threadlocal throw transactionsafe transactionsafedynamic true try typedef typeid typename union unsigned using virtual void volatile wchart while xor xor_eq

Language features

Feature Supported Token Example
Access Modifiers
Virtual function
class Animal {
  // Intentionally not virtual:
  void Move(void) {
    std::cout << "This animal moves in some way" << std::endl;
  virtual void Eat(void) = 0;

// The class "Animal" may possess a definition for Eat if desired.
class Llama : public Animal {
  // The non virtual function Move is inherited but not overridden.
  void Eat(void) override {
    std::cout << "Llamas eat grass!" << std::endl;
Vector& Vector::operator+=(const Vector& rhs)
    for (int i = 0; i < length; ++i)
        value[i] += rhs.value[i];
    return *this;
Operator Overloading
Multiple Inheritance
using namespace std;

// Variable created inside namespace
namespace first
  int val = 500;
// Global variable
int val = 100;
// Ways to do it:
namespace ns_name { declarations }
inline namespace ns_name { declarations }
namespace { declarations }
using namespace ns_name;
using ns_name::name;
namespace name = qualified-namespace ;
namespace ns_name::inline(since C++20)(optional) name { declarations } 
Function Overloading
// volume of a cube
int volume(const int s) {
 return s*s*s;
// volume of a cylinder
double volume(const double r, const int h) {
  return 3.1415926*r*r*static_cast(h);
std::vector items;
items.push_back(5);  // Append integer value '5' to vector 'items'.
items.push_back(2);  // Append integer value '2' to vector 'items'.
items.push_back(9);  // Append integer value '9' to vector 'items'.

for (auto it = items.begin(); it != items.end(); ++it) {  // Iterate through 'items'.
  std::cout << *it;  // And print value of 'items' for current index.
class Foobar {
  Foobar(double r = 1.0,
         double alpha = 0.0)  // Constructor, parameters with default values.
      : x_(r * cos(alpha))    // <- Initializer list
    y_ = r * sin(alpha);  // <- Normal assignment

  double x_;
  double y_;
Foobar a,
       c(5, M_PI/4);
Single Dispatch
Partial Application
// bind example
#include      // std::cout
#include    // std::bind

// a function: (also works with function object: std::divides my_divide;)
double my_divide (double x, double y) {return x/y;}

struct MyPair {
  double a,b;
  double multiply() {return a*b;}

int main () {
  using namespace std::placeholders;    // adds visibility of _1, _2, _3,...

  // binding functions:
  auto fn_five = std::bind (my_divide,10,2);               // returns 10/2
  std::cout << fn_five() << '\n';                          // 5

  auto fn_half = std::bind (my_divide,_1,2);               // returns x/2
  std::cout << fn_half(10) << '\n';                        // 5

  auto fn_invert = std::bind (my_divide,_2,_1);            // returns y/x
  std::cout << fn_invert(10,2) << '\n';                    // 0.2

  auto fn_rounding = std::bind (my_divide,_1,_2);     // returns int(x/y)
  std::cout << fn_rounding(10,3) << '\n';                  // 3

  MyPair ten_two {10,2};

  // binding members:
  auto bound_member_fn = std::bind (&MyPair::multiply,_1); // returns x.multiply()
  std::cout << bound_member_fn(ten_two) << '\n';           // 20

  auto bound_member_data = std::bind (&MyPair::a,ten_two); // returns ten_two.a
  std::cout << bound_member_data() << '\n';                // 10

  return 0;
Scientific Notation
While Loops
Case Sensitivity
Assignment =
Switch Statements
switch(expression) {
   case true  :
   default :
Print() Debugging std::cout
MultiLine Comments /* */
/* A comment
Line Comments //
// A comment
Increment and decrement operators
Zero-based numbering
Variadic Functions
double average(int count, ...)
Manual Memory Management
int main(void)
  int *poin = malloc(4);
#define min(X, Y)  ((X) < (Y) ? (X) : (Y))
  x = min(a, b);          →  x = ((a) < (b) ? (a) : (b));
  y = min(1, 2);          →  y = ((1) < (2) ? (1) : (2));
  z = min(a + 28, *p);    →  z = ((a + 28) < (*p) ? (a + 28) : (*p));
int pldb = 80766866;
File Imports
//  If a header file is included within <>, the preprocessor will search a predetermined directory path to locate the header file. If the header file is enclosed in "", the preprocessor will look for the header file in the same directory as the source file.
#include "stdio.h"
Type Casting
double da = 3.3;
double db = 3.3;
double dc = 3.4;
int result = (int)da + (int)db + (int)dc; //result == 9
#define height 10
// C/C++ program to check if a number is 
// even or not using goto statement 
using namespace std; 
// function to check even or not 
void checkEvenOrNot(int num) 
    if (num % 2 == 0) 
        goto even; // jump to even 
        goto odd; // jump to odd 
    cout << num << " is evenn"; 
    return; // return if even 
    cout << num << " is oddn"; 
// Driver program to test above function 
int main() 
    int num = 26; 
    return 0; 
struct account {
  int account_number;
  char *first_name;
  char *last_name;
  float balance;
/* hello world */
// hi
Symbol Tables
// Declare an external function
extern double bar(double x);

// Define a public function
double foo(int count)
    double  sum = 0.0;

    // Sum all the values bar(1) to bar(count)
    for (int i = 1;  i <= count;  i++)
        sum += bar((double) i);
    return sum;
// Symbol Table:
// Symbol name|Type|Scope
// bar|function, double|extern
// x|double|function parameter
// foo|function, double|global
// count|int|function parameter
// sum|double|block local
// i|int|for-loop statement
Bitwise Operators
int i = 4; /* bit pattern equivalent is binary 100 */
int j = i << 2; /* makes it binary 10000, which multiplies the original number by 4 i.e. 16 */
Assert Statements
int i, a[10];
for (i = 0; i < 10; ++i)
  assert(0 <= i && i < 10);
  a[i] = 10-i;
for (i = 0; i < 10; ++i)
  assert(0 <= i && i < 10);
  assert(0 <= a[i] && a[i] < 10);
  a[a[i]] = a[i];
Strings "
"hello world"
int *ptr;
Ternary operators
int main(void) { printf("%d", 1 ? 1 : 0); }
char character = 'P';
Booleans true false
enum Gender {
Magic Getters and Setters X
Fixed Point Numbers X
Case Insensitive Identifiers X
Semantic Indentation X
Garbage Collection X
Regular Expression Syntax Sugar X
Variable Substitution Syntax X

Books about C++ from ISBNdb

title authors year publisher
ADTs, Data Structures, and Problem Solving with C++ Nyhoff 2011 PEARSON INDIA
Data Structures & Algorithm Analysis in C++ Weiss, Mark 2013 Pearson
C++ Primer (5th Edition) Lippman, Stanley and Lajoie, Josée and Moo, Barbara 2012 Addison-Wesley Professional
Data Structures with C++ Using STL Ford, William and Topp, William 2001 Pearson
Introduction to Programming with C++ (Myprogramminglab) Liang, Y. Daniel 2013 Pearson
C++ How to Program (Early Objects Version) (9th Edition) Deitel, Paul and Deitel, Harvey 2013 Pearson
C++ Programming: Program Design Including Data Structures Malik, D. S. 2014 Cengage Learning
Engineering Problem Solving with C++ (3rd Edition) Etter, Delores M. and Ingber, Jeanine A. 2011 Pearson
Problem Solving With C++ Savitch, Walter 2011 Pearson
C++ How to Program: Late Objects Version (How to Program (Deitel)) Deitel, Paul and Deitel, Harvey 2010 Pearson
C++ Programming Today Johnston, Barbara 2007 Pearson
C++ for Java Programmers Weiss, Mark 2003 Pearson
C++ for Everyone Horstmann, Cay S. 2010 Wiley
Data Structures Using C and C++ (2nd Edition) Langsam, Yedidyah and Augenstein, Moshe J. and Tenenbaum, Aaron M. 1995 Pearson
Introduction to Programming with C++ Zak, Diane 2012 Cengage Learning
Data Structures And Algorithm Analysis in C++ Weiss, Mark Allen 2006 Pearson College Div
C++ Plus Data Structures Dale, Nell 2011 Jones & Bartlett Learning
Developing Series 60 Applications: A Guide for Symbian OS C++ Developers: A Guide for Symbian OS C++ Developers Edwards, Leigh and Barker, Richard and Staff of EMCC Software Ltd. 2004 Addison-Wesley Professional
The C++ Programming Language (3rd Edition) Stroustrup, Bjarne 1997 Addison-Wesley Professional
C++ Standard Library, The: A Tutorial And Reference 2Nd Edition NICOLAI M JOSUTTIS 2012 PEARSON INDIA
Starting Out with Games & Graphics in C++ Gaddis, Tony 2012 Pearson
Problem Solving with C++ Savitch, Walter 2008 Addison Wesley
Programming And Problem Solving With C++ Dale, Nell 2009 Jones & Bartlett Learning
Introduction to C++ Programming, Brief Edition D. S. Malik 2009 Course Technology
Programming: Principles and Practice Using C++ Stroustrup, Bjarne 2008 Addison-Wesley Professional
C++ Programming: From Problem Analysis to Program Design Malik, D. S. 2008 Cengage Learning
An Introduction to Computing Using C++ and Object Technology Ford, William H. and Topp, William R. 1998 Pearson
C++ Template Metaprogramming Abrahams, David 2004 Addison-Wesley Professional
C++ Programming: Program Design Including Data Structures (MindTap Course List) Malik, D. S. 2017 Cengage Learning
C++ Programs to Accompany Programming Logic and Design Smith, Jo Ann 2012 Course Technology
C++ for Everyone Horstmann, Cay S. 2011 Wiley
C++ Programming: From Problem Analysis to Program Design (Introduction to Programming) Malik, D. S. 2010 Cengage Learning
Understanding Programming: An Introduction Using C++ Cannon, Scott R. 2000 Course Technology
Absolute C++ (4th Edition) Savitch, Walter 2009 Pearson
C++ from the Ground Up: Learn C++ from the Master Schildt, Herbert 1994 Mcgraw-Hill Osborne Media
Hands-On Embedded Programming with C++17: Create versatile and robust embedded solutions for MCUs and RTOSes with modern C++ Posch, Maya 2019 Packt Publishing
C++ How to Program plus MyProgrammingLab with Pearson eText -- Access Card Package (9th Edition) Deitel, Paul and Deitel, Harvey 2013 Pearson
C++ GUI Programming with Qt 4 (2nd Edition) (Prentice Hall Open Source Software Development Series) Blanchette, Jasmin and Summerfield, Mark 2008 Prentice Hall
C++ from the Ground Up, Third Edition Schildt, Herbert 2003 McGraw-Hill Education
Object-Oriented Programming Using C++ (Introduction to Programming) Farrell, Joyce 2008 Cengage Learning
Problem Solving with C++ Plus MyLab Programming with Pearson eText -- Access Card Package Savitch, Walter 2017 Pearson
C++ How to Program (6th Edition) Deitel, Paul J. 2007 Prentice Hall
Algorithms in C++ Sedgewick, Robert 1992 Addison-Wesley Pub (Sd)
Professional C++ Solter, Nicholas A. and Kleper, Scott J. 2005 Wrox
Parallel Scientific Computing in C++ and MPI: A Seamless Approach to Parallel Algorithms and their Implementation Karniadakis, George Em 2003 Cambridge University Press
C++ GUI Programming with Qt 4 Blanchette, Jasmin and Summerfield, Mark 2006 Prentice Hall PTR
C++ Primer Lippman, Stanley B. and Lajoie, Josee and Moo, Barbara E. 2005 Addison-Wesley Professional
Enough Rope to Shoot Yourself in the Foot: Rules for C and C++ Programming (Unix/C) Holub, Allen I. 1995 Computing McGraw-Hill
Assembly Language and Computer Architecture Using C++ and Java™ Dos Reis, Anthony J. 2004 Course Technology
Advanced CORBA® Programming with C++ Henning, Michi and Vinoski, Steve 1999 Addison-Wesley Professional
Introduction to Programming with C++ (2nd Edition) Liang, Y. Daniel 2009 Pearson
Programming in C++ Dewhurst, Stephen 1989 Pearson Ptr
C++ Programming in easy steps McGrath, Mike 2011 In Easy Steps Limited
C++ Gotchas: Avoiding Common Problems in Coding and Design Dewhurst, Stephen C. 2002 Addison-Wesley Professional
MyLab Programming with Pearson eText -- Access Card -- for Starting Out with C++ from Control Structures to Objects (My Programming Lab) Gaddis, Tony 2017 Pearson
Object Oriented Programming In C++ Johnsonbaugh, Richard and Kalin, Martin 1994 Macmillan Coll Div
Ivor Horton's Beginning Visual C++ 2010 Horton, Ivor 2010 Wrox
C++ Programming And Fundamental Concepts Anderson Jr., Arthur E. 2008 Pearson
C++ All-In-One Desk Reference For Dummies Mueller, John Paul and Cogswell, Jeff 2009 For Dummies
Inside the C++ Object Model Lippman, Stanley B. 1996 Addison-Wesley Professional
Boost.Asio C++ Network Programming Torjo, John 2013 Packt Publishing
C++ Network Programming, Volume 2: Systematic Reuse with ACE and Frameworks Debbie Lafferty and Schmidt, Douglas and Huston, Stephen 2002 Addison-Wesley Professional
Essential C++ Lippman, Stanley B. 1999 Addison-Wesley Professional
Beginning C++ Game Programming Horton, John 2016 Packt Publishing
An Introduction to C++ and Numerical Methods Ortega, James M. and Grimshaw, Andrew S. 1998 Oxford University Press
Mylab Programming with Pearson Etext -- Access Card -- For Problem Solving with C++ Savitch, Walter 2014 Pearson
The Waite Group's Object-Oriented Programming in C++ Lafore, Robert and Waite Group 1998 Sams
Microsoft Visual C++ Windows Applications by Example: Code and explanation for real-world MFC C++ Applications Stefan Björnander 2008 Packt Publishing
C++ How to Program (4th Edition) Deitel, Harvey M. and Deitel, Paul J. 2002 Prentice Hall
C++ For C Programmers, Third Edition (3rd Edition) Pohl, Ira 1998 Addison-Wesley Professional
Numerical Methods in Finance with C++ (Mastering Mathematical Finance) Capinski, Maciej J. 2012 Cambridge University Press
Object-Oriented Programming in C++ Josuttis, Nicolai M. 2002 Wiley
Beginning C++ Through Game Programming, Second Edition Dawson, Michael 2006 Cengage Learning PTR
C++ Programming Ullman, Larry E. and Signer, Andreas 2005 Peachpit Pr
Advanced Metaprogramming in Classic C++ Di Gennaro, Davide 2015 Apress
C++ Primer Plus (Mitchell Waite Signature Series) Prata, Stephen 1998 Waite Group Pr
Expert C++ Programming: Leveraging the power of modern C++ to build scalable modular applications Swaminathan, Jeganathan and Posch, Maya and Galowicz, Jacek 2018 Packt Publishing
C++ The Core Language: A Foundation for C Programmers (Nutshell Handbooks) Brown, Doug and Satir, Gregory 1995 O'Reilly & Associates
Learn Microsoft Visual C++ 6.0 Now Sphar, Chuck 1999 Microsoft Press
Mylab Programming with Pearson Etext -- Access Code Card -- For Absolute C++ Savitch, Walter and Mock, Kenrick 2015 Pearson
Programming With Class: Introduction To Computer Science With C++ Kamin, Samuel N. and Reingold, Edward M. 1995 McGraw-Hill College
C++ Common Knowledge: Essential Intermediate Programming: Essential Intermediate Programming Dewhurst, Stephen 2005 Addison-Wesley Professional
C++ Standard Library Practical Tips (Programming Series) Reese, Greg 2005 Charles River Media
Sams Teach Yourself C++ in 21 Days (Sams Teach 21 Days) Liberty, Jesse 2001 Sams
Microsoft Mastering: MFC Development Using Microsoft Visual C++ 6.0 (DV-DLT Mastering) Microsoft Press 2000 Microsoft Press
C++ Network Programming, Volume I: Mastering Complexity with ACE and Patterns: Mastering Complexity with ACE and Patterns Schmidt, Douglas and Huston, Stephen 2001 Addison-Wesley Professional
Functional Programming in C++: How to improve your C++ programs using functional techniques Cukic, Ivan 2018 Manning Publications
Hackish C++ Games & Demos Michael Flenov 2006 A-list Publishing
Using Motif With C++ (sigs: Advances In Object Technology) Daniel J. Bernstein 1998 Sigs
C++ Program Design Davidson 2001 Irwin Professional Publishing
C++ primer Lippman, Stanley B 1989 Addison-Wesley
Programming and Problem Solving With C++ Dale, Nell B. and Weems, Chip and Headington, Mark and Dale, Nell 1996 Jones & Bartlett Pub
C++ Timesaving Techniques For Dummies Telles, Matthew 2005 For Dummies
Unix System Programming Using C++ Chan, Terrence 2021 Prentice Hall of India
C++ by Example (Programming Series) Perry, Greg M. 1992 Que Pub
Schaum's Outlines - Programming With C++ Hubbard, John R. and Hubbard, John R. 1996 Mcgraw-Hill
Programming for Graphics Files: In C and C++ Levine, John R. and Levine, John 1994 Wiley
Modern C++ for Absolute Beginners: A Friendly Introduction to C++ Programming Language and C++11 to C++20 Standards Dmitrović, Slobodan 2020 Apress
C++ Plus Data Structures Dale, Nell 2003 Jones And Bartlett Publishers
C++ Windows Programming Bjornander, Stefan 2016 Packt Publishing
An Introduction to Programming With C++ (Available Titles Skills Assessment Manager (SAM) - Office 2010) Zak, Diane 2007 Course Technology
Introduction to C++ Programming and Graphics Pozrikidis, Constantine 2007 Springer
Windows Animation Programming With C++ Young, Michael J. 1994 Morgan Kaufmann Pub
Problem Solving, Abstraction & Design Using C++ (5th Edition) Friedman, Frank L. and Koffman, Elliot B. 2006 Addison Wesley
Object-Oriented Programming with C++ (Oxford Higher Education) Sahay, Sourav 2006 Oxford University Press
C++ Programming Language, The Bjarne, Stroustrup 2013 Addison-Wesley Professional
C++ Programming with Design Patterns Revealed Muldner, Tomasz 2001 Pearson
Speech Recognition: Theory and C++ Implementation Becchetti, Claudio and Ricotti, Lucio Prina 1999 Wiley
Schaum's Easy Outline: Programming with C++ Hubbard, John R. 1999 McGraw-Hill
C++ and Object Oriented Programming Irvine, Kip R. 1996 Prentice Hall
Object-Oriented Programming in C++ (2nd Edition) Johnsonbaugh, Richard and Kalin, Martin 1999 Pearson
Practical C++ Financial Programming Oliveira, Carlos 2015 Apress
Ivor Horton's Beginning Visual C++ 2012 Horton, Ivor 2012 Wrox
Financial Instrument Pricing Using C++ Duffy, Daniel J. 2004 Wiley
Sams Teach Yourself C++ in 21 Days, Third Edition Liberty, Jesse 1999 Sams
Program Development and Design Using C++ Bronson, Gary J. 2005 Course Technology
A Jump Start Course In C++ Programming James W. Cooper and Richard B. Lam 1995 Wiley-interscience
Borland C++ Power Programming/Book and Disk Walnum, Clayton 1993 Que Pub
Practical C++ McGregor, Robert W. 1999 Que Pub
C++ Gui Programming With Qt 4 Blanchette, Jasmin. 2008 Prentice Hall In Association With Trolltech Press
Starting Out With C++: Brief Version Update, Visual C++ .net (4th Edition) Tony Gaddis and Barret Krupnow 2005 Addison Wesley
Object-oriented Programming with C++ E Balagurusamy 1997 TBS
C++ Programming In Easy Steps McGrath, Mike 2008 In Easy Steps Limited
Stl Tutorial & Reference Guide: C++ Programming With the Standard Template Library (Addison-Wesley Professional Computing Series) Musser, David R. and Saini, Atul 1996 Addison-Wesley
Boost.Asio C++ Network Programming Cookbook: Over 25 hands-on recipes to create robust and highly-effi cient cross-platform distributed applications with the Boost.Asio library Radchuk, Dmytro 2016 Packt Publishing
Starting Out With The C++ (2nd Brief Edition) Tony Gaddis 2000 Scott Jones
Data Structures Through C++: Experience Data Structures C++ through animations Kanetkar, Yashavant 2019 BPB Publications

Publications about C++ from Semantic Scholar

title authors year citations influentialCitations
C++ Programming Language B. Stroustrup 1986 7014 230
TOPAS and TOPAS-Academic: an optimization program integrating computer algebra and crystallographic objects written in C++ A. Coelho 2018 627 27
Advanced C++ Programming Styles and Idioms J. Coplien 1991 468 14
Introduction to the GiNaC Framework for Symbolic Computation within the C++ Programming Language Christian Bauer and A. Frink and R. Kreckel 2000 389 39
Supporting Students in C++ Programming Courses with Automatic Program Style Assessment Kirsti Ala-Mutka and Toni Uimonen and Hannu-Matti Järvinen 2004 84 6
An Overview of the C++ Programming Language B. Stroustrup 1999 24 3
html.html · cpp.html · xml.html

View source

- Build the next great programming language · Search · Day 213 · About · Blog · Acknowledgements · Traffic · Traffic Today · GitHub ·