C is a general-purpose, procedural, low-level programming language that forms the foundation of modern software systems. Operating systems, compilers, embedded systems, databases, networking stacks, and even higher-level languages are built on top of C.
1. What Is C?
C was created by Dennis Ritchie at Bell Labs in the early 1970s to build the UNIX operating system.
Core Characteristics
- Procedural language
- Compiled (not interpreted)
- Statically typed
- Close to hardware
- Manual memory management
- Extremely fast and portable
2. High-Level Architecture of C Programs
C sits between hardware and operating systems.
Hardware
↓
Assembly
↓
C Language
↓
Operating System
↓
Applications
C provides:
- Direct memory access
- Predictable performance
- Minimal runtime overhead
3. C Compilation Architecture (Internal Flow)
C code does not run directly. It goes through multiple stages.
Compilation Pipeline
.c source file
↓
Preprocessor
↓
Compiler
↓
Assembler
↓
Linker
↓
Executable
Detailed Steps
1. Preprocessing
Handles:
#include#define-
#ifdef
#include <stdio.h>
#define PI 3.14
Output: Expanded source code
2. Compilation
- Converts C code to assembly
- Performs syntax & semantic checks
3. Assembly
- Converts assembly to machine code (
.ofiles)
4. Linking
- Resolves symbols
- Links libraries
- Produces final executable
4. Memory Architecture in C (Very Important)
C exposes memory directly.
Memory Layout of a C Program
High Address
│ Stack
│ ↓
│ Heap
│ ↑
│ BSS Segment
│ Data Segment
│ Text Segment
Low Address
Segments Explained
Text Segment
- Machine code
- Read-only
Data Segment
- Initialized global/static variables
int x = 10;
BSS Segment
- Uninitialized globals/statics
int y;
Heap
- Dynamic memory (
malloc,free)
Stack
- Function calls
- Local variables
5. Basic Structure of a C Program
#include <stdio.h>
int main(void) {
printf("Hello, World\n");
return 0;
}
Components
- Preprocessor directives
-
main()function - Statements
- Return value
6. Tokens in C (Language Building Blocks)
C programs are made of tokens.
Types of Tokens
- Keywords
- Identifiers
- Constants
- Strings
- Operators
- Punctuators
7. Keywords in C (Complete List)
auto break case char
const continue default do
double else enum extern
float for goto if
inline int long register
restrict return short signed
sizeof static struct switch
typedef union unsigned void
volatile while
8. Data Types in C
Primitive Types
char
int
float
double
Modifiers
short
long
signed
unsigned
Derived Types
- Arrays
- Pointers
- Structures
- Unions
- Functions
9. Variables and Constants
Variable Declaration
int age = 25;
Constants
const int MAX = 100;
#define PI 3.14
10. Operators in C (Complete)
Arithmetic
+ - * / %
Relational
== != > < >= <=
Logical
&& || !
Bitwise
& | ^ ~ << >>
Assignment
= += -= *= /= %= <<= >>=
Unary
++ -- sizeof & *
11. Control Flow Statements
if-else
if (x > 0) {
printf("Positive");
} else {
printf("Negative");
}
switch
switch (n) {
case 1: break;
default: break;
}
12. Loops in C
for Loop
for (int i = 0; i < 10; i++) {
printf("%d\n", i);
}
while Loop
while (x > 0) {
x--;
}
do-while
do {
x--;
} while (x > 0);
13. Functions in C
Function Declaration
int add(int a, int b);
Definition
int add(int a, int b) {
return a + b;
}
Function Call
int sum = add(3, 4);
14. Storage Classes (Internal Behavior)
auto
Default local variable
static
Preserves value between calls
static int count;
extern
Refers to external variable
register
Hints CPU register usage
15. Arrays
int arr[5] = {1,2,3,4,5};
Multidimensional Array
int matrix[2][3];
16. Pointers (Core of C)
Pointer Declaration
int *p;
Pointer Assignment
int x = 10;
p = &x;
Dereferencing
printf("%d", *p);
17. Pointer Arithmetic
p++;
p--;
*(p + 1);
18. Dynamic Memory Management
malloc
int *p = malloc(5 * sizeof(int));
calloc
int *p = calloc(5, sizeof(int));
realloc
p = realloc(p, 10 * sizeof(int));
free
free(p);
19. Structures
struct Person {
char name[20];
int age;
};
Access
struct Person p;
p.age = 30;
20. Unions
union Data {
int i;
float f;
};
Memory shared between members.
21. typedef
typedef unsigned int uint;
uint x = 10;
22. Enums
enum Day {MON, TUE, WED};
23. File Handling
File Pointer
FILE *fp;
Open File
fp = fopen("file.txt", "r");
Read / Write
fprintf(fp, "Hello");
fscanf(fp, "%d", &x);
Close
fclose(fp);
24. Preprocessor Directives
Macros
#define SQUARE(x) (x*x)
Conditional Compilation
#ifdef DEBUG
#endif
25. Error Handling
if (ptr == NULL) {
perror("Memory error");
}
26. Undefined Behavior (Critical Concept)
Examples:
- Dereferencing NULL
- Buffer overflow
- Using uninitialized variables
C does not protect you.
27. C Standard Libraries
Common headers:
stdio.h
stdlib.h
string.h
math.h
time.h
ctype.h
28. C Standards
- C89 / C90
- C99
- C11
- C17
- C23
Each adds features and refinements.
29. Where C Is Used Today
- Operating Systems (Linux, Windows kernel)
- Embedded systems
- Game engines
- Databases
- Compilers
- Drivers
- Networking stacks
30. Why Learning C Matters
- Understand memory
- Understand performance
- Understand how computers work
- Foundation for C++, Rust, Go, Java, Python internals
Final Thoughts
C is not easy, but it is honest.
It exposes the machine exactly as it is.
If you truly understand C, you understand computers.
Top comments (1)
Why is this tagged
#csharp? C# is a totally separate language.BTW, clang is written in C++, not C.
All that aside, I agree with your premise as I stated in the preface of my book Why Learn C.