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

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

C बहुत पहले operating systems लिखने के लिए बनाई गई थी और अभी भी fast और simple होने के लिए पसंद की जाती है। इसके features आपको सीधे memory के साथ काम करने देते हैं।

C का इतिहास

Dennis Ritchie ने 1972 में Bell Labs में C को Unix operating system दोबारा लिखने के एक tool के तौर पर design किया, जो पहले हर specific machine के लिए assembly में लिखा गया था। C ने पहली बार Unix को hardware में portable बनाया।

उदाहरण: History of C

c
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
	// Print formatted text to the screen
	printf("C was created by Dennis Ritchie at Bell Labs in 1972.");
	// Return 0 to signal that the program finished successfully
	return 0;
}

Direct Memory Access

Pointers एक variable को सीधे एक value की बजाय किसी दूसरे variable का memory address store करने देते हैं, ताकि आप data को indirectly पढ़ या modify कर सकें।

यही वजह है कि C में dynamic memory allocation और efficient array/string handling जैसी techniques possible हैं।

उदाहरण: Direct Memory Access

c
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
	// Declare value and set it to 42
	int value = 42;
	int *ptr = &value;
	// Print formatted text to the screen
	printf("Address: %p, Value via pointer: %d", (void*)ptr, *ptr);
	// Return 0 to signal that the program finished successfully
	return 0;
}

Speed और Efficiency

आपके code और processor के बीच कोई garbage collector, virtual machine, या interpreter layer न होने से, एक compiled C program अपना execution time actual work करने में लगाता है, runtime overhead manage करने में नहीं -- यही एक कारण है कि यह अभी भी performance-critical systems के लिए चुना जाता है।

उदाहरण: Speed and Efficiency

c
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
	// Declare sum and set it to 0
	long sum = 0;
	// Loop: repeat while the condition holds
	for (long i = 0; i < 1000000; i++) {
		sum += i;
	}
	// Print formatted text to the screen
	printf("Sum: %ld", sum);
	// Return 0 to signal that the program finished successfully
	return 0;
}

Modularity

C एक program को छोटे, independent functions में तोड़ने को बढ़ावा देती है, हर एक एक task handle करता है और file में कहीं से भी (या headers के जरिए दूसरी files से भी) callable होता है। यह दिखाता है कि बड़े real-world codebases बढ़ने के साथ maintainable कैसे रहते हैं।

उदाहरण: Modularity

c
// Include standard input/output (printf, scanf)
#include <stdio.h>
int square(int n) {
	// Send n * n back to the caller
	return n * n;
}
// Program execution starts in main()
int main() {
	// Print formatted text to the screen
	printf("Square: %d", square(5));
	// Return 0 to signal that the program finished successfully
	return 0;
}

Extensibility

Standard library और third-party libraries reusable functionality -- string handling, math, file I/O -- को header files के जरिए expose करती हैं जिन्हें आप #include करते हैं, ताकि आपको common operations दोबारा लिखने में फंसना न पड़े जिन्हें दूसरे programmers पहले ही अच्छे से solve कर चुके हैं।

उदाहरण: Extensibility

c
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Include string functions (strlen, strcpy, ...)
#include <string.h>
// Program execution starts in main()
int main() {
	char name[] = "C Language";
	// Print formatted text to the screen
	printf("Length: %zu", strlen(name));
	// Return 0 to signal that the program finished successfully
	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. C को पुराना होने की वजह से obsolete मान लेना, जबकि यह अभी भी operating systems और embedded software के पीछे की language है।
  2. यह मान लेना कि C आपके लिए array bounds या pointer validity check करता है, जबकि यह बिना किसी safety net के direct memory access देता है।
  3. यह सोचना कि सारे C compilers same तरह behave करते हैं, जबकि standard (C89, C99, C11) और compiler extensions यह बदल सकते हैं कि क्या allowed है।

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.