C History & Features
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
// 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;
}
Login to try C/C++/Java/PHP code in the editor
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
// 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;
}
Login to try C/C++/Java/PHP code in the editor
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
// 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;
}
Login to try C/C++/Java/PHP code in the editor
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
// 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;
}
Login to try C/C++/Java/PHP code in the editor
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
// 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;
}
Login to try C/C++/Java/PHP code in the editor
- Assuming C is obsolete because it is old, when it is still the language behind operating systems and embedded software.
- Believing C checks array bounds or pointer validity for you, when it gives direct memory access with no safety net.
- Thinking all C compilers behave the same way, when the standard (C89, C99, C11) and compiler extensions can change what is allowed.
Chapter Quiz — Complete all 21 topics to unlock
0/21 topics done
Complete these topics first:
- C Introduction
- C History & Features
- C Environment Setup
- C First Program
- C Syntax & Structure
- C Statements
- C Comments
- C Keywords & Identifiers
- C Data Types
- C Character Data Type
- C Numeric Data Types
- C Decimal (Floating-Point) Numbers
- C sizeof Operator
- C Extended Data Types
- C Type Conversion
- C Booleans
- C Variables
- C Changing Variable Values
- C Multiple Variables
- C Constants
- C Fixed-Width Integers