Introduction to C
Explore the history of C, set up your development environment, and write your first program.
A Brief History of C
C was developed by Dennis Ritchie at Bell Labs in 1972 as a successor to the B language. It was originally designed for systems programming, particularly the Unix operating system. Over the decades C has become one of the most influential programming languages ever created, serving as the foundation for languages like C++, Java, and Go. The ANSI C standard was formalized in 1989, and the language continues to be updated through the ISO standards process.
Setting Up Your Environment
To write and compile C programs you need a C compiler such as GCC or Clang. On Linux you can install GCC with your package manager, and on macOS Clang is included with Xcode Command Line Tools. Windows users can install MinGW or use the Windows Subsystem for Linux. A simple text editor or an IDE like VS Code with the C/C++ extension will make development more productive.
Your First C Program
Every C program begins execution at the main function. The stdio.h header file provides standard input and output functions including printf, which writes formatted text to the console. The return statement at the end of main provides an exit code to the operating system, where zero conventionally indicates success. Let us walk through a complete Hello World program.
#include <stdio.h>
int main(void) {
printf("Hello, World!\n");
return 0;
}
Compiling and Running
To compile a C source file you invoke the compiler from the command line, passing the source file and an output flag. The compiler translates your human-readable code into machine code that the processor can execute directly. Understanding the compilation process is important because C gives you much more control over the final binary than higher-level languages do.
# Compile the program
gcc -o hello hello.c
# Run the program
./hello