1. Introduction to C Programming
Introduction to C Programming
C is a statically typed procedural language that offers high performance and close-to-hardware abstractions. It was developed by Dennis Ritchie at Bell Labs between 1969 and 1973. C remains one of the most influential programming languages in history, serving as the foundation for operating systems, embedded systems, and countless other languages.
Unlike high-level languages that abstract away memory management, C gives you direct control over memory through pointers and manual allocation. This power comes with responsibility — C requires you to manage memory explicitly, which leads to efficient programs but also to subtle bugs if you're not careful.
Why Learn C?
C is the language of systems programming. Understanding C gives you insight into how computers actually work at the memory and processor level. Many modern languages — including C++, Java, Python, and Rust — draw concepts from C.
- Operating Systems — Linux, Windows, and macOS kernels are written primarily in C
- Embedded Systems — Microcontrollers and IoT devices run C code
- Performance — C produces fast, efficient machine code
- Foundation — Learning C makes you a better programmer in all languages
Your First C Program
The tradition in C programming is to start with a program that prints Hello, World! to the screen. This demonstrates the basic structure of a C program.
The #include directive tells the preprocessor to include the standard input/output library. The main() function is the entry point of every C program. printf() outputs text to the console, and return 0 indicates successful execution.
Compilation Stages
C code goes through four distinct stages before becoming an executable program:
- Preprocessing — Handles directives like #include and #define, expanding macros and including header files
- Compilation — Converts the preprocessed code into assembly language specific to your CPU
- Assembly — Converts assembly code into machine code (object files)
- Linking — Combines object files with libraries to create the final executable
You can stop at any stage using compiler flags. For example, gcc -E stops after preprocessing, and gcc -S stops after compilation.
Compiling and Running
To compile a C program, you need a C compiler. The most common compiler is GCC (GNU Compiler Collection).
If you don't specify an output name with -o, GCC creates a file named a.out by default. On Windows, the executable will have a .exe extension.
Knowledge Check
Ready to test your understanding of 1. Introduction to C Programming?