Released · improving
Programming language · Since 1972
C is a small, portable systems programming language that compiles to fast native code and gives you direct control over memory and hardware.
C is a general-purpose, procedural programming language designed by Dennis Ritchie at Bell Labs to write the Unix operating system. It was later standardized by ANSI and ISO, and the standard is now maintained by the ISO/IEC JTC1/SC22/WG14 committee; revisions such as C99, C11 and C17 are widely used. The language has few keywords and is built from simple pieces (functions, structs and pointers) that the compiler translates directly into machine code.
C shines where predictable performance, small binaries and direct control over memory matter: operating system kernels, device drivers, microcontroller firmware, language runtimes and databases. Nearly every platform has a C compiler, and the C calling convention (ABI) is the common ground other languages use to call into each other's libraries. The trade-off is that C has no bounds checking or automatic memory management, so preventing buffer overflows and use-after-free bugs is the programmer's job.
To get started, install GCC, Clang or MSVC and compile small programs from the terminal. A typical learning path goes from variables and types to control flow, functions, arrays and strings, pointers, structs and finally dynamic memory. Turn on warnings with -Wall -Wextra, look up the standard library on cppreference, and get into the habit of tracking down memory errors with AddressSanitizer and GDB.
Pointers give direct access to memory addresses, and malloc and free let you manage memory yourself, so you decide exactly how data is laid out and how resources are used.
The language is small and defined by an ISO standard, so standard-conforming code can be recompiled for a wide range of operating systems and processors.
C compiles to native machine code with almost no runtime, which makes it usable even for firmware and bootloaders that run without an operating system.
The C function interface serves as a de facto standard ABI, so languages such as Python, Rust and Go can call C libraries directly through their FFI.
On Debian or Ubuntu Linux, install GCC and Make with the command below (on Fedora, use sudo dnf install gcc make). On macOS, run xcode-select --install to get the Xcode Command Line Tools, which include Clang. On Windows, install MSYS2 and run pacman -S mingw-w64-ucrt-x86_64-gcc in the UCRT64 shell, or install Visual Studio Build Tools with the Desktop development with C++ workload.
sudo apt install build-essentialOpen a new terminal and make sure the compiler prints its version. On macOS the gcc command points to Apple Clang, so you will see a Clang version. If you installed MSVC, run cl in the Developer Command Prompt instead.
gcc --versionSave the first program as hello.c, then compile it with warnings enabled against the C17 standard and run it. With MSVC, compile with cl /W4 hello.c and run hello.exe.
gcc -Wall -Wextra -std=c17 hello.c -o hello && ./hello#include <stdio.h> brings in the standard I/O header that declares printf. The main function is where the program starts, and (void) means it takes no arguments. printf prints the string, and \n is a newline. return 0 tells the operating system that the program finished successfully. gcc compiles the source into an executable named hello, and ./hello runs it.
hello.c
#include <stdio.h>
int main(void) {
printf("Hello, world!\n");
return 0;
}
gcc hello.c -o hello && ./helloSix chapters that take you from installation to the core ideas of C.
Ask questions, share experience and trade opinions about C.
No discussions yet. Start the first one.
0 comments
Sign in · Sign in to leave a comment.
Be the first to comment.