← Back to C++ Course | Chapter 1: Introduction & Basics | Lesson 2 of 15

C++ History & Features

C++ grew out of the older C language, adding the idea of building programs from objects. Its features make it very fast and flexible, with lots of ready-made tools.

History of C++

Bjarne Stroustrup began designing C++ in 1979 at Bell Labs, originally calling it 'C with Classes' because his goal was simply to add object-oriented features on top of the existing C language.

The name changed to C++ in 1983, using the increment operator as a pun for 'one step beyond C'.

Example: History of C++

cpp
#include <iostream>

int main() {
	// Bjarne Stroustrup began "C with Classes" in 1979 at Bell Labs;
	// renamed C++ in 1983 -- ++ as a pun for "one step beyond C".
	std::cout << "C++ began life in 1979 as 'C with Classes'" << std::endl;
	return 0;
}

Object-Oriented Programming

The biggest feature C++ added over plain C was object-oriented programming: classes let you bundle data and the functions that operate on it into a single reusable unit called an object.

This makes large codebases easier to reason about, since related state and behavior live together instead of being scattered across loose functions and structs.

Example: Object-Oriented Programming

cpp
// Include std::cout and std::cin
#include <iostream>

// Define the type Car
class Car {
// Members below can be accessed from outside the class
public:
	int speed = 0;
	void accelerate() { speed += 10; }
};

// Program execution starts in main()
int main() {
	Car car;
	car.accelerate();
	// Print to the console with cout
	std::cout << "Speed: " << car.speed << std::endl;
	// Return 0 to signal that the program finished successfully
	return 0;
}

Speed and Efficiency

Because C++ compiles straight down to native machine instructions rather than running through an interpreter or virtual machine, there's very little overhead between your code and the CPU actually executing it.

That raw speed is exactly why performance-critical engines, including the tooling behind cookiescursor.com, are built in C++ instead of a higher-level language.

Example: Speed and Efficiency

cpp
#include <iostream>

int main() {
	// No interpreter or VM -- compiles straight to native instructions.
	std::cout << "C++ compiles directly to machine code for minimal overhead" << std::endl;
	return 0;
}

Rich Library Support

The Standard Template Library (STL) ships with every standard C++ compiler and gives you ready-made, well-tested data structures like vector, list, and stack along with algorithms to search and sort them.

Using the STL instead of writing your own linked list or sort function saves time and avoids a whole class of manual-memory bugs.

Example: Rich Library Support

cpp
// Include std::cout and std::cin
#include <iostream>
// Include std::vector
#include <vector>
#include <algorithm>

// Program execution starts in main()
int main() {
	// Create a vector named nums (a resizable array)
	std::vector<int> nums = {5, 2, 8, 1};
	std::sort(nums.begin(), nums.end());
	// Print to the console with cout
	std::cout << "Sorted first element: " << nums[0] << std::endl;
	// Return 0 to signal that the program finished successfully
	return 0;
}

Extensibility

C++ has kept evolving through numbered standards like C++11, C++14, C++17, and C++20, each adding modern conveniences such as lambda expressions, smart pointers, and structured bindings.

This means code written today can be noticeably shorter and safer than the same logic written in older C++ style, while still compiling to the same fast machine code.

Example: Extensibility

cpp
#include <iostream>

int main() {
	// C++11 lambda expression -- a modern convenience added by later standards
	auto square = [](int x) { return x * x; };
	std::cout << "Square: " << square(5) << std::endl;
	return 0;
}
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
Common Mistakes
  1. Assuming C++ features like auto or lambdas work in any compiler setting, when they need a modern standard such as -std=c++11 or newer on older compilers.
  2. Believing C++ automatically manages memory like Java, when raw new memory must be freed with delete unless you use smart pointers.
  3. Treating C++ as purely object-oriented and forcing everything into classes, although it is multi-paradigm and free functions are perfectly normal.

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.