C++: Difference between revisions
Created article 'C++' with auto-categories 🏷️ |
m Created article 'C++' with auto-categories 🏷️ |
||
Line 1: | Line 1: | ||
'''C++''' is a general-purpose [[programming language]] | '''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 | 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 | 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++ | 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). | ||
Significant milestones in C++'s evolution include: | |||
* ''' | * '''1989''': C++ 2.0 introduced multiple inheritance and abstract classes. | ||
* '''1998''' | * '''1998''': The first ISO C++ standard (C++98) was published, formalizing the language. | ||
* '''2011''' | * '''2011''': C++11 introduced major features like lambda expressions, smart pointers, and concurrency support. | ||
* '''2020''' | * '''2020''': C++20 added concepts, ranges, and coroutines. | ||
The language continues to evolve, with new standards | 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 | 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 | 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 | C++ supports: | ||
* ''' | * '''Classes and objects''' for encapsulation. | ||
* ''' | * '''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; | |||
} | |||
The STL provides templated containers (e.g., `vector`, `map`) and algorithms (e.g., `sort`, `find`). | |||
=== | === Concurrency === | ||
C++ | 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 | C++ is used in diverse domains due to its performance and versatility: | ||
* | |||
* | === Systems Programming === | ||
* | * Operating systems (e.g., [[Windows NT|Windows]], [[Linux kernel|Linux]]). | ||
* | * Device drivers and embedded systems. | ||
=== 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 | C++ remains a cornerstone of modern computing due to: | ||
* '''Performance''' | * '''Performance''': Outperforms many higher-level languages in speed. | ||
* '''Portability''' | * '''Portability''': Runs on virtually all hardware platforms. | ||
* '''Legacy Codebase''' | * '''Legacy Codebase''': Powers critical infrastructure (e.g., banking systems). | ||
Despite competition from | 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 (programming language)]] – The predecessor of C++. | ||
* [[Java (programming language) | * [[Java (programming language)]] – A higher-level OOP language. | ||
* [[Python (programming language) | * [[Python (programming language)]] – A dynamically typed language often contrasted with C++. | ||
* [[Rust (programming language) | * [[Rust (programming language)]] – A modern language emphasizing safety and concurrency. | ||
== References == | == References == | ||
* | * ISO/IEC 14882:2020 – C++20 standard. | ||
* | * Stroustrup, B. ''The C++ Programming Language'' (4th ed.). | ||
* | * C++ Foundation. (2023). ''C++ Core Guidelines''. | ||
[[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]] |