C++ is a programming language created in 1985 by Bjarne Stroustrup.
#7on PLDB | 38Years Old | 4.1mUsers |
128Books | 6Papers | 2mRepos |
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...
// Type your code here, or load an example.
int square(int num) {
return num * num;
}
#include <iostream>
int main() {
std::cout << "Hello, world!" << std::endl;
return 0;
}
#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;
}
#include <cstdint>
namespace Gui
{
}
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{vec.at(4)}; // 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 vec.at(4)
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 }
#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
Feature | Supported | Token | Example |
---|---|---|---|
Access Modifiers | ✓ | ||
Exceptions | ✓ | ||
Classes | ✓ | ||
Threads | ✓ | ||
Virtual function | ✓ | class Animal { public: // 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 { public: // The non virtual function Move is inherited but not overridden. void Eat(void) override { std::cout << "Llamas eat grass!" << std::endl; } }; |
|
Templates | ✓ | template |
|
Operator Overloading | ✓ | ||
Multiple Inheritance | ✓ | ||
Namespaces | ✓ | #include |
|
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 |
|
Iterators | ✓ | std::vector |
|
Constructors | ✓ | class Foobar { public: 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 } private: double x_; double y_; }; Foobar a, b(3), c(5, M_PI/4); |
|
Single Dispatch | ✓ | ||
Partial Application | ✓ | // http://www.cplusplus.com/reference/functional/bind/ // bind example #include |
|
Scientific Notation | ✓ | ||
Conditionals | ✓ | ||
Constants | ✓ | ||
While Loops | ✓ | ||
Case Sensitivity | ✓ | ||
Assignment | ✓ | = | |
Switch Statements | ✓ | switch(expression) { case true : break; default : // break; } |
|
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 | ✓ | #include |
|
Macros | ✓ | // https://learn.microsoft.com/en-us/cpp/preprocessor/macros-c-cpp?redirectedfrom=MSDN&view=msvc-170 // https://gcc.gnu.org/onlinedocs/cpp/Macro-Arguments.html #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)); |
|
Integers | ✓ | 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 |
|
Type Casting | ✓ | double da = 3.3; double db = 3.3; double dc = 3.4; int result = (int)da + (int)db + (int)dc; //result == 9 |
|
Directives | ✓ | #include |
|
Gotos | ✓ | // C/C++ program to check if a number is // even or not using goto statement #include |
|
Structs | ✓ | struct account { int account_number; char *first_name; char *last_name; float balance; }; |
|
Comments | ✓ | /* 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 | ✓ | #include |
|
Strings | ✓ | " | "hello world" |
Pointers | ✓ | int *ptr; |
|
Ternary operators | ✓ | #include |
|
Characters | ✓ | char character = 'P'; |
|
Booleans | ✓ | true false | |
Enums | ✓ | enum Gender { Male, Female, }; |
|
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 |
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 |