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

C History & Features

C was created a long time ago to write operating systems and is still loved for being fast and simple. Its features let you work directly with memory.

History of C

Dennis Ritchie designed C at Bell Labs in 1972 as a tool for rewriting the Unix operating system, which had previously been written in assembly for each specific machine. C let Unix become portable across hardware for the first time.

Example: 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 let a variable store the memory address of another variable instead of a value directly, so you can read or modify data indirectly.

This is what makes techniques like dynamic memory allocation and efficient array/string handling possible in C.

Example: 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 and Efficiency

With no garbage collector, virtual machine, or interpreter layer between your code and the processor, a compiled C program spends its execution time doing actual work rather than managing runtime overhead -- one reason it's still chosen for performance-critical systems.

Example: 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 encourages breaking a program into small, independent functions, each handling one task and callable from anywhere in the file (or other files, via headers). This mirrors how larger real-world codebases stay maintainable as they grow.

Example: 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

The standard library and third-party libraries expose reusable functionality -- string handling, math, file I/O -- through header files you #include, so you're not stuck rewriting common operations that other programmers have already solved well.

Example: 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. #}
Common Mistakes
  1. Assuming C is obsolete because it is old, when it is still the language behind operating systems and embedded software.
  2. Believing C checks array bounds or pointer validity for you, when it gives direct memory access with no safety net.
  3. Thinking all C compilers behave the same way, when the standard (C89, C99, C11) and compiler extensions can change what is 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.