C++ का इतिहास और विशेषताएँ
In this page:
C++ का इतिहास
Bjarne Stroustrup ने 1979 में Bell Labs में C++ design करना शुरू किया, originally इसे 'C with Classes' कहते हुए क्योंकि उनका goal बस existing C language के ऊपर object-oriented features add करना था।
नाम 1983 में C++ में बदला, increment operator को 'C से एक कदम आगे' के लिए एक pun की तरह इस्तेमाल करते हुए।
उदाहरण: History of C++
#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;
}
Login to try C/C++/Java/PHP code in the editor
Object-Oriented Programming
plain C के ऊपर C++ ने सबसे बड़ा feature जो add किया वह object-oriented programming था: classes आपको data और इस पर operate करने वाले functions को एक single reusable unit में bundle करने देती हैं जिसे object कहा जाता है।
यह large codebases के बारे में reason करना आसान बनाता है, क्योंकि related state और behavior साथ रहते हैं loose functions और structs में बिखरे होने की बजाय।
उदाहरण: Object-Oriented Programming
// 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;
}
Login to try C/C++/Java/PHP code in the editor
Speed और Efficiency
क्योंकि C++ एक interpreter या virtual machine से गुज़रने की बजाय सीधे native machine instructions में compile होता है, आपके code और actually इसे execute करने वाले CPU के बीच बहुत कम overhead होता है।
यही raw speed exactly वह वजह है कि cookiescursor.com के पीछे के tooling समेत performance-critical engines किसी higher-level language की बजाय C++ में बनाए जाते हैं।
उदाहरण: Speed and Efficiency
#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;
}
Login to try C/C++/Java/PHP code in the editor
Rich Library Support
Standard Template Library (STL) हर standard C++ compiler के साथ आती है और आपको vector, list, और stack जैसी ready-made, well-tested data structures उन्हें search और sort करने वाले algorithms के साथ देती है।
अपनी खुद की linked list या sort function लिखने की बजाय STL इस्तेमाल करना समय बचाता है और manual-memory bugs की एक पूरी class से बचाता है।
उदाहरण: Rich Library Support
// 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;
}
Login to try C/C++/Java/PHP code in the editor
Extensibility
C++11, C++14, C++17, और C++20 जैसे numbered standards के जरिए evolve होता रहा है, हर एक lambda expressions, smart pointers, और structured bindings जैसी modern conveniences add करते हुए।
इसका मतलब है आज लिखा code पुरानी C++ style में लिखी same logic से noticeably छोटा और safer हो सकता है, फिर भी same fast machine code में compile होते हुए।
उदाहरण: Extensibility
#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;
}
Login to try C/C++/Java/PHP code in the editor
- यह मान लेना कि
autoया lambdas जैसे C++ features किसी भी compiler setting में काम करते हैं, जब पुराने compilers पर उन्हें-std=c++11या नए जैसे एक modern standard चाहिए। - यह मानना कि C++ Java की तरह automatically memory manage करता है, जब raw
newmemory को smart pointers इस्तेमाल न करने परdeleteसे free करना ज़रूरी है। - C++ को purely object-oriented मानना और सब कुछ classes में force करना, हालांकि यह multi-paradigm है और free functions बिल्कुल normal हैं।
Chapter Quiz — Complete all 15 topics to unlock
0/15 topics done
Complete these topics first: