C Language Introduction
⏱️ Estimated time: 15 minutes | Difficulty: Beginner
Table of Contents
What is C Programming?
C is a general-purpose, procedural programming language developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories. It was originally developed to write the UNIX operating system. C is considered the mother of all modern programming languages because most compilers, JVMs, and kernels are written in C, and most programming languages follow C syntax (like C++, Java, and Python's CPython implementation).
Note on Evolution
Despite being over 50 years old, C remains one of the most widely used programming languages today due to its performance, simplicity, and low-level memory access capabilities.
Why Should We Learn C?
Learning C builds a solid foundation for understanding how computers actually function under the hood.
- C is a middle-level language. It bridges the gap between machine-level languages and high-level languages, allowing for both system programming (like OS creation) and application programming.
- It provides incredibly fast execution speed compared to interpreted languages like Python or Java since it is directly compiled to machine code.
- Direct manipulation of hardware and memory through pointers gives programmers immense control.
- C is the lingua franca of embedded systems ranging from smartwatches and microwaves to industrial robots.
First C Program (Hello World)
Let's look at the absolute simplest program you can write in C. This program just prints the words "Hello World" to the screen.
// Simple C program to display "Hello World"
#include <stdio.h>
int main() {
// Print statement
printf("Hello World");
return 0;
}
Try It Yourself
Space Complexity: O(1) as no extra memory is statically allocated.
Explanation of the C Program
Let us break down the program line-by-line to understand how a C program actually works.
#include <stdio.h>
This is a preprocessor command that tells the C compiler to include the Standard Input Output library stdio.h before compiling the source code. Without this, we couldn't use the printf() function!
int main()
This is the main function. Every C program must have a main() function. Execution of the program always starts at the main function, no matter where it is located in the code.
{ ... }
Curly brackets define a block of code. The code inside the brackets forms the body of the main function.
printf("Hello World");
printf() is a standard library function used to print data to the console. Notice the semicolon ; at the end. In C, every statement must end with a semicolon!
return 0;
The return 0; statement terminates the main() function and returns the integer 0 to the operating system. Returning 0 typically means the program executed successfully without any errors.
Applications of C
- Operating Systems: Windows, Linux, UNIX, and Android kernel parts are written in C.
- Embedded Systems: Microcontrollers and microprocessors rely heavily on C for fast, low-footprint execution.
- Databases: Popular databases like MySQL, PostgreSQL, and Oracle are primarily written in C/C++.
- Compilers: Most modern language compilers (even for Python, Java's JVM) are written in C.
- Game Engines: Early hardware-restricted games and base engines rely on C for its unparalleled speed.