C++: Difference between revisions

Bot (talk | contribs)
Created article 'C++' with auto-categories 🏷️
 
Bot (talk | contribs)
m Created article 'C++' with auto-categories 🏷️
 
Line 1: Line 1:
'''C++''' is a general-purpose [[programming language]] created as an extension of the [[C (programming language)|C language]]. It is widely used for [[systems programming]], [[game development]], and applications requiring high performance. C++ supports multiple programming paradigms, including [[procedural programming]], [[object-oriented programming]], and [[generic programming]]. Known for its efficiency and flexibility, C++ remains one of the most popular programming languages in the industry.
'''C++''' is a general-purpose [[programming language]] that was developed as an extension of the [[C (programming language)|C programming language]]. It is widely used for system/software development, game programming, and performance-critical applications due to its efficiency, flexibility, and object-oriented features. C++ supports multiple programming paradigms, including procedural, object-oriented, and generic programming.


== Introduction ==
== Introduction ==
C++ was developed by [[Bjarne Stroustrup]] in 1979 at [[Bell Labs]] as an enhancement to C. The language introduces features such as [[classes (computer programming)|classes]], [[virtual function]]s, and [[templates (C++)|templates]], enabling more complex and reusable code structures. C++ is standardized by the [[International Organization for Standardization|ISO]], with updates released periodically to improve functionality and security.
C++ is a statically typed, compiled language known for its high performance and fine-grained control over system resources. It was designed with an emphasis on systems programming, embedded systems, and large-scale software development. Unlike higher-level languages, C++ allows direct manipulation of hardware and memory, making it suitable for applications where performance is critical.


The language is commonly used in performance-critical applications, including [[operating systems]], [[web browsers]], and [[video games]]. Its ability to directly manipulate hardware and memory makes it a preferred choice for low-level programming tasks.
The language is standardized by the [[International Organization for Standardization|ISO]], with revisions published periodically to introduce new features and improvements. C++ is used in operating systems (e.g., [[Microsoft Windows|Windows]], [[Linux]]), game engines (e.g., [[Unreal Engine]]), and high-frequency trading systems.
 
Key features of C++ include:
* '''Object-oriented programming (OOP)''': Supports classes, inheritance, polymorphism, and encapsulation.
* '''Template metaprogramming''': Enables generic programming through templates.
* '''Low-level memory manipulation''': Provides pointers and manual memory management.
* '''Standard Template Library (STL)''': A rich library of containers, algorithms, and iterators.


== History or Background ==
== History or Background ==
C++ originated from Stroustrup's work on improving C for [[systems programming]]. The initial version, called "C with Classes," added object-oriented features to C. In 1983, the language was renamed C++, reflecting the increment operator (++) in C.
C++ was created by [[Bjarne Stroustrup]] at [[Bell Labs]] in 1979 as an extension of C. Initially named "C with Classes," the language aimed to add object-oriented features while retaining C's efficiency. The first commercial release appeared in 1985, and the language was renamed C++ (where "++" signifies an increment over C).


Key milestones in C++'s development include:
Significant milestones in C++'s evolution include:
* '''1985''' – The first commercial release of C++.
* '''1989''': C++ 2.0 introduced multiple inheritance and abstract classes.
* '''1998''' The first ISO standard (C++98) was published.
* '''1998''': The first ISO C++ standard (C++98) was published, formalizing the language.
* '''2011''' C++11 introduced major updates, including [[lambda expressions]], [[smart pointers]], and [[thread (computing)|multithreading support]].
* '''2011''': C++11 introduced major features like lambda expressions, smart pointers, and concurrency support.
* '''2020''' C++20 added features like [[concepts (C++)|concepts]] and [[coroutines]].
* '''2020''': C++20 added concepts, ranges, and coroutines.


The language continues to evolve, with new standards proposed every few years.
The language continues to evolve, with new standards (C++23, C++26) under development to improve usability and performance.


== Technical Details or Architecture ==
== Technical Details or Architecture ==
C++ is a [[statically typed]], [[compiled language]] that provides low-level memory access while maintaining high-level abstractions. Its core features include:
C++ is designed to provide high-level abstractions while allowing low-level control. Its architecture includes several core components:
 
=== Syntax and Semantics ===
C++ inherits most of C's syntax but extends it with additional constructs. A simple C++ program structure includes:
#include <iostream>
using namespace std;
 
int main() {
    cout << "Hello, World!" << endl;
    return 0;
}
 
Key syntactic elements:
* '''Headers''' (e.g., `<iostream>`) for library inclusion.
* '''Namespaces''' (e.g., `std`) to avoid naming conflicts.
* '''Functions''' with explicit return types.


=== Memory Management ===
=== Memory Management ===
C++ allows both manual memory management (using [[new and delete (C++)|new and delete]]) and automatic management (via [[smart pointers]]). This flexibility is crucial for performance optimization but requires careful handling to avoid [[memory leak]]s.
C++ allows both automatic (stack) and dynamic (heap) memory allocation. Manual memory management is done via `new` and `delete`, though modern C++ encourages smart pointers (`unique_ptr`, `shared_ptr`) for safer resource handling.


=== Object-Oriented Features ===
=== Object-Oriented Features ===
* '''Classes and Objects''' – Encapsulation, inheritance, and polymorphism.
C++ supports:
* '''Virtual Functions''' – Enable runtime [[dynamic dispatch]].
* '''Classes and objects''' for encapsulation.
* '''Multiple Inheritance''' – A class can inherit from multiple base classes.
* '''Inheritance''' (single, multiple, virtual).
* '''Polymorphism''' through virtual functions.
 
Example:
class Animal {
public:
    virtual void speak() = 0; // Pure virtual function
};
 
class Dog : public Animal {
public:
    void speak() override {
        cout << "Woof!" << endl;
    }
};
 
=== Templates and Generic Programming ===
Templates enable writing code that works with any data type:
template <typename T>
T max(T a, T b) {
    return (a > b) ? a : b;
}


=== Generic Programming ===
The STL provides templated containers (e.g., `vector`, `map`) and algorithms (e.g., `sort`, `find`).
* '''Templates''' – Allow writing code that works with any data type.
* '''Standard Template Library (STL)''' – Provides containers (e.g., [[vector (C++)|vector]], [[list (C++)|list]]) and algorithms (e.g., [[sort (C++)|sort]], [[find (C++)|find]]).


=== Performance Optimization ===
=== Concurrency ===
C++ supports [[inline expansion|inline functions]], [[compile-time evaluation]], and [[zero-cost abstractions]], ensuring minimal runtime overhead.
C++11 introduced threading support via `<thread>`, mutexes, and futures. Example:
#include <thread>
void task() {
    cout << "Thread running" << endl;
}
 
int main() {
    thread t(task);
    t.join();
    return 0;
}


== Applications or Use Cases ==
== Applications or Use Cases ==
C++ is used in a wide range of domains due to its performance and versatility. Some notable applications include:
C++ is used in diverse domains due to its performance and versatility:
* '''Operating Systems''' – [[Linux]], [[Windows]], and [[macOS]] kernels use C++ for critical components.
 
* '''Game Development''' – Engines like [[Unreal Engine]] and [[Unity (game engine)|Unity]] rely on C++ for high-performance rendering.
=== Systems Programming ===
* '''Embedded Systems''' – Used in [[microcontrollers]], [[automotive systems]], and [[IoT]] devices.
* Operating systems (e.g., [[Windows NT|Windows]], [[Linux kernel|Linux]]).
* '''High-Frequency Trading''' – Financial institutions use C++ for low-latency trading algorithms.
* Device drivers and embedded systems.
* '''Web Browsers''' – [[Google Chrome|Chrome]], [[Mozilla Firefox|Firefox]], and [[Microsoft Edge|Edge]] are built with C++.
 
=== Game Development ===
* Game engines like [[Unreal Engine]] and [[Unity (game engine)|Unity]] (partially).
* Physics engines and real-time rendering.
 
=== High-Performance Computing ===
* Financial modeling and high-frequency trading.
* Scientific simulations (e.g., [[NASA]] projects).
 
=== Web Browsers and Databases ===
* Rendering engines (e.g., [[Blink (browser engine)|Blink]], [[Gecko (software)|Gecko]]).
* Database systems (e.g., [[MySQL]], [[MongoDB]]).


== Relevance in Computing or Industry ==
== Relevance in Computing or Industry ==
C++ remains a cornerstone of modern software development due to its:
C++ remains a cornerstone of modern computing due to:
* '''Performance''' – Near-hardware execution speed.
* '''Performance''': Outperforms many higher-level languages in speed.
* '''Portability''' Runs on almost all platforms, from embedded devices to supercomputers.
* '''Portability''': Runs on virtually all hardware platforms.
* '''Legacy Codebase''' – Many critical systems are written in C++, ensuring its continued use.
* '''Legacy Codebase''': Powers critical infrastructure (e.g., banking systems).
* '''Community and Ecosystem''' – A vast number of libraries (e.g., [[Boost (C++ libraries)|Boost]]) and tools (e.g., [[GCC]], [[Clang]]) support C++ development.


Despite competition from newer languages like [[Rust (programming language)|Rust]] and [[Go (programming language)|Go]], C++ maintains strong adoption in industries where performance is paramount.
Despite competition from languages like [[Rust (programming language)|Rust]] and [[Go (programming language)|Go]], C++ is still preferred for performance-critical applications. The active standardization process ensures its continued relevance.


== See also ==
== See also ==
* [[C (programming language)|C]] – The predecessor of C++.
* [[C (programming language)]] – The predecessor of C++.
* [[Java (programming language)|Java]] – Another object-oriented language influenced by C++.
* [[Java (programming language)]] – A higher-level OOP language.
* [[Python (programming language)|Python]] – Often used alongside C++ for scripting.
* [[Python (programming language)]] – A dynamically typed language often contrasted with C++.
* [[Rust (programming language)|Rust]] – A modern language emphasizing memory safety.
* [[Rust (programming language)]] – A modern language emphasizing safety and concurrency.
* [[Standard Template Library]] – A core part of C++'s library.


== References ==
== References ==
* [https://isocpp.org/ ISO C++ Foundation]
* ISO/IEC 14882:2020 – C++20 standard.
* [https://www.stroustrup.com/ Bjarne Stroustrup's homepage]
* Stroustrup, B. ''The C++ Programming Language'' (4th ed.).
* [https://en.cppreference.com/ C++ reference documentation]
* C++ Foundation. (2023). ''C++ Core Guidelines''.
* [https://www.open-std.org/jtc1/sc22/wg21/ ISO C++ Standards Committee]


[[Category:Programming languages]]
[[Category:Programming languages]]
[[Category:Object-oriented programming languages]]
[[Category:Object-oriented programming languages]]
[[Category:C programming language family]]
[[Category:C programming language family]]