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

C++ का इतिहास और विशेषताएँ

C++ पुरानी C language से बढ़ी, objects से programs बनाने का idea add करते हुए। इसके features इसे बहुत fast और flexible बनाते हैं, बहुत सारे ready-made tools के साथ।

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++

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

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

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 और 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

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

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

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++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

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. #}
आम गलतियां
  1. यह मान लेना कि auto या lambdas जैसे C++ features किसी भी compiler setting में काम करते हैं, जब पुराने compilers पर उन्हें -std=c++11 या नए जैसे एक modern standard चाहिए।
  2. यह मानना कि C++ Java की तरह automatically memory manage करता है, जब raw new memory को smart pointers इस्तेमाल न करने पर delete से free करना ज़रूरी है।
  3. C++ को purely object-oriented मानना और सब कुछ classes में force करना, हालांकि यह multi-paradigm है और free functions बिल्कुल 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.