Home › Categories › Programming & Languages › C (programming language)

C (programming language)

From WikiTech, the encyclopedia of technology

Technology · Programming & Languages · 5 min read · 941 words · Updated

C (programming language)
Technology
C (programming language) — article photograph or illustration
Image placeholderPlace the file shown below in the assets/articles folder
File: c-language.webp
DesignerDennis Ritchie
First appeared1972
ParadigmProcedural, imperative
TypingStatic, weak
StandardISO/IEC 9899 (latest: C23)

C is a general-purpose, statically typed, procedural programming language designed for writing system software.[1] It gives programmers direct access to memory and maps closely to what the hardware does, while still being portable across processors. It has been among the most widely used languages for more than fifty years.

C was developed by Dennis Ritchie at Bell Labs and is closely tied to the Unix operating system. Most of the kernels and system libraries that run today's computers, including Linux, contain large amounts of C.

History

In the late 1960s Ken Thompson and Ritchie were building Unix on a small PDP-7 and later a PDP-11. Thompson wrote a language called B, derived from BCPL, which worked on word-addressed machines but lacked types and handled bytes poorly. Ritchie extended it between 1971 and 1973 with data types and structures, creating C.[1]

By 1973 the Unix kernel had been rewritten in C. This was a landmark: an operating system written in a high-level language could be moved to new hardware by porting the compiler instead of rewriting everything in assembly. In 1978 Brian Kernighan and Ritchie published The C Programming Language, whose informal definition became known as K&R C.

Standardisation

ANSI approved the first formal standard in 1989, usually called C89, and ISO adopted it as C90. Later revisions added features while keeping the language small:

VersionYearNotable additions
C991999// comments, inline, variable-length arrays, stdint.h, long long
C112011Threads, atomics, _Static_assert, _Generic
C172018Bug fixes and clarifications only
C232024nullptr, constexpr, #embed, bool as a keyword, binary literals

The standard is published as ISO/IEC 9899.[2] Compilers such as GCC, Clang and MSVC implement it with various extensions.

Language design

C has a small core: functions, structures, pointers, arrays, a preprocessor and a minimal standard library. It has no classes, no garbage collector and no built-in strings. Key characteristics include:

  • Pointers. A pointer holds a memory address. Arrays and pointers are closely related, and pointer arithmetic is a normal operation.
  • Manual memory management. Programs allocate heap memory with malloc and release it with free.
  • Preprocessor. Directives such as #include and #define perform textual substitution before compilation.
  • Weak static typing. Types are checked at compile time, but implicit conversions and casts are common.
  • Separate compilation. Source files compile to object files that a linker combines, with declarations shared through header files.
#include <stdio.h>
#include <stdlib.h>

int main(void) {
    int n = 5;
    int *a = malloc(n * sizeof *a);
    if (!a) return 1;
    for (int i = 0; i < n; i++) a[i] = i * i;
    printf("%d\n", a[4]);   /* prints 16 */
    free(a);
    return 0;
}

Undefined behaviour and safety

The standard leaves the result of some operations undefined, such as reading beyond the end of an array, using freed memory or overflowing a signed integer. Compilers may assume these never happen and optimise accordingly, so a bug can behave unpredictably. Memory errors in C programs are a major source of security vulnerabilities such as buffer overflows. Tools including sanitizers, static analysers and bounds-checking compiler options help, and newer languages such as Rust aim to prevent these classes of bugs by design.

Where C is used

C remains dominant where control and small size matter:

  • Operating system kernels, device drivers and firmware
  • Embedded systems and microcontrollers
  • Language runtimes, including the reference implementation of Python
  • Databases such as PostgreSQL and libraries such as SQLite
  • Compilers, network stacks and cryptographic libraries

Because almost every platform offers a C compiler, C also acts as a common interface between languages. Many other languages call C libraries through a foreign function interface, and the C calling convention is the de facto standard for binary APIs.

Influence

C's syntax shaped a large family of languages. C++ began as an extension of it, and Objective-C, Java, C#, Go, JavaScript and Rust all borrow its curly-brace blocks, operators and control structures. Together with Unix, C also influenced the way later systems were designed, from the use of plain text files to the idea of small portable tools.

Relationship to C++

C and C++ are separate languages today. Most C code compiles as C++ with small changes, but not all of it does. C++ adds classes, templates and a much larger library, while C keeps a deliberately small feature set. The two standards evolve independently, though they share ideas.

Portability and systems programming

C's influence comes partly from the way its language model maps to common machine operations. The language gives programmers direct access to memory through pointers, while keeping source code independent of a particular processor's assembly syntax. A compiler can translate the same program for different architectures, provided the program stays within the language standard and the target platform supplies the required libraries. This balance made C useful for operating systems, embedded software and portable utilities.

The same low-level control creates risks. Incorrect pointer arithmetic, out-of-bounds access and lifetime mistakes can corrupt memory or expose security vulnerabilities. Modern projects use compiler warnings, static analysis, sanitizers, code review and safer library conventions to reduce those risks. C remains valuable, but its flexibility should be paired with disciplined interfaces and testing.

Editorial connections and engineering implications

The C abstract machine and undefined behaviour

The C standard describes an abstract machine rather than a fixed processor. A compiler may transform a program while preserving the observable behaviour required by the standard. This flexibility enables optimisation, but undefined behaviour is not a predictable request for a particular hardware action. Signed integer overflow, invalid pointer use and accessing an object outside its lifetime can invalidate assumptions the compiler is allowed to make.

C also needs to be distinguished from operating-system interfaces. ISO C defines language and library behaviour, while POSIX specifies many process, file and threading interfaces used on Unix-like systems. Manual memory management gives programmers control, but each allocation needs an owner, a lifetime and a reliable cleanup path. Buffer lengths should accompany pointers, input should be validated, and error paths must release resources. C remains important because its toolchains and ABIs are mature; Rust is increasingly considered for new components where stronger memory-safety guarantees are valuable.

See also

  • C++ – A general-purpose, statically typed language that extends C with classes, templates and zero-overhead abstractions.
  • Rust – A compiled systems programming language that enforces memory safety through ownership and borrowing without a garbage collector.
  • Dennis Ritchie – American computer scientist who created the C programming language and co-created Unix.
  • Garbage Collection – Automatic memory management in which a runtime reclaims memory that a program can no longer reach.
  • POSIX – A family of IEEE standards that specify a portable interface for Unix-like operating systems.
  • Python – A high-level, dynamically typed programming language that emphasises readability.
  • Grace Hopper – American computer scientist and United States Navy rear admiral who developed an early compiler.
  • JavaScript – The programming language that powers interactive web pages and a large ecosystem of browser, server and desktop software.

References

  1. ↑ Ritchie (1993), The Development of the C Language (bell-labs.com)
  2. ↑ ISO/IEC 9899, Programming languages - C (iso.org)
  3. ↑ cppreference.com, C language (en.cppreference.com)