C++ परिचय
In this page:
C++ क्या है?
C++ एक powerful, general-purpose programming language है जो C के एक extension की तरह बनाई गई। इसे अक्सर एक middle-level language कहा जाता है क्योंकि यह आपको low-level code लिखने देती है जो सीधे memory और hardware से बात करता है, साथ ही classes और templates जैसे high-level abstractions भी support करती है।
उदाहरण: What is C++?
#include <iostream>
int main() {
// C++ extends C: low-level memory/hardware access plus
// high-level abstractions like classes and templates.
std::cout << "C++ is a middle-level, general-purpose language" << std::endl;
return 0;
}
Login to try C/C++/Java/PHP code in the editor
C++ क्यों सीखें?
C++ सीखना worth है क्योंकि यह large codebases को maintainable रखने वाले object-oriented structure को छोड़े बिना आपको performance और memory पर fine control देती है।
cookiescursor.com के पीछे के systems जैसे performance-sensitive backends बनाने वाली companies specifically इसी speed-and-structure combination के लिए C++ चुनती हैं।
उदाहरण: Why Learn C++?
// Include std::cout and std::cin
#include <iostream>
// Program execution starts in main()
int main() {
// Print to the console with cout
std::cout << "C++ combines fine performance control with OOP structure" << std::endl;
// Return 0 to signal that the program finished successfully
return 0;
}
Login to try C/C++/Java/PHP code in the editor
C++ कैसे काम करता है
एक compiled language की तरह, आपकी C++ source file इसके चलने से पहले पूरी तरह एक compiler से native machine code में translate होती है।
क्योंकि वह translation runtime पर line-by-line की बजाय पहले से होता है, resulting program एक interpreted language से तेज़ start और execute होता है।
उदाहरण: How C++ Works
// g++ program.cpp -o program (compiles ahead of time to machine code)
// ./program (runs instantly -- no interpreter needed)
#include <iostream>
int main() {
std::cout << "Compiled once, then runs as native machine code" << std::endl;
return 0;
}
Login to try C/C++/Java/PHP code in the editor
C++ के Applications
C++ वहाँ दिखता है जहाँ raw speed और hardware control मायने रखते हैं: operating system kernels, browser engines, और real-time game engines सब आमतौर पर इसमें लिखे जाते हैं।
Databases और system utilities भी C++ पर depend करते हैं ताकि वे memory और I/O precisely manage कर सकें, इस काम को एक runtime पर छोड़ने की बजाय।
उदाहरण: Applications of C++
// Include std::cout and std::cin
#include <iostream>
// Program execution starts in main()
int main() {
// Print to the console with cout
std::cout << "Used in OS kernels, browser engines, game engines, and databases" << std::endl;
// Return 0 to signal that the program finished successfully
return 0;
}
Login to try C/C++/Java/PHP code in the editor
C++ के Benefits
C++ आपको pointers के जरिए memory तक direct access देती है, जो exactly वह चीज़ है जो आपको लगभग बिना किसी runtime overhead के code लिखने देती है।
Operating systems में same portability, manual memory control के साथ combined, यही वजह है कि जब हर byte और हर cycle मायने रखता है तो C++ पसंदीदा language बनी रहती है।
उदाहरण: Benefits of C++
// Include std::cout and std::cin
#include <iostream>
// Program execution starts in main()
int main() {
// Declare value and set it to 42
int value = 42;
int* ptr = &value;
// Print to the console with cout
std::cout << "Direct memory access via pointer: " << *ptr << std::endl;
// Return 0 to signal that the program finished successfully
return 0;
}
Login to try C/C++/Java/PHP code in the editor
- यह सोचना कि C++ code सीधे एक script की तरह चलता है, जब इसे पहले compile करना होता है (उदाहरण के लिए
g++ main.cpp -o main) और फिर produced executable run होता है। - यह मान लेना कि C++ बस कुछ extras वाली C है और यह ignore करना कि यह अपनी standard library वाली एक अलग language है, जैसे
std::stringऔरstd::vector। - एक
.cppfile कोgccजैसे C compiler से C mode में compile करना और#include <iostream>याstd::coutपर errors पाना।
Chapter Quiz — Complete all 15 topics to unlock
0/15 topics done
Complete these topics first: