Lably
Skip to content

C (programming language)

General-purpose programming language

  • 44 min read
  • 8 chapters

Related on Lably

Through Operating system, Application software and Compiler

C was initially developed as a successor to the B programming language at Bell Labs by Ritchie between 1972 and 1973. Its initial purpose was to construct utilities running on Unix, and was later applied to re-implementing the kernel of the Unix operating system. During the 1980s, C gradually gained popularity, leading to it becoming one of the most widely used programming languages, with C compilers available for practically all modern computer architectures and operating systems. The book The C Programming Language, co-authored by the original language designer, served for many years as the de facto standard for the language. C has been standardized since 1989 by the American National Standards Institute (ANSI) and, subsequently, jointly by the International Organization for Standardization (ISO) and the International Electrotechnical Commission (IEC).

C is an imperative procedural language, supporting structured programming, lexical variable scope, and recursion, with a static type system. It was designed to be compiled to provide low-level access to memory and language constructs that map efficiently to machine instructions, all with minimal runtime support. Despite its low-level capabilities, the language was designed to encourage cross-platform programming. A standards-compliant C program written with portability in mind can be compiled for a wide variety of computer platforms and operating systems with few changes to its source code.

Although neither C nor its standard library provide some popular features found in other languages, it is flexible enough to support them. For example, object orientation and garbage collection are provided by external libraries GLib Object System and Boehm garbage collector, respectively.

Since 2000, C has typically ranked as the most or second-most popular language in the TIOBE index.

Characteristics

C is an imperative, procedural language with a free-form source layout. Statements are terminated by semicolons and grouped into blocks using curly braces. All executable code is contained in functions rather than top-level statements. The language has a relatively small number of keywords, and user-defined identifiers are not distinguished from keywords by any sigil.

Parameters are passed by value; pass-by-reference is achieved with pointers. A function's return value may be ignored, and while a function cannot normally be nested inside another function, some translators support this. C supports recursion, and run-time polymorphism may be achieved using function pointers. Control flow is provided through constructs such as if, for, do, while, and switch. The language offers arithmetic; bitwise; and logical operators including +, +=, ++, &, ||, and multiple assignments may be performed in a single statement. A variable declared inside a block is accessible only within that block and only below its declaration.

Data typing is weakly enforced and static, with implicit conversion between primitive types. User-defined types allow aliasing of type specifiers. Arrays are defined and accessed with square-bracket notation, for example month[11]. User-defined structure types let related data elements be passed and copied as a unit, though two structures cannot be compared without custom code to compare each field. Unions support overlapping members, allowing multiple data types to share the same memory location, and enumeration types support aliasing integer values. C lacks a dedicated string type but provides syntax for null-terminated strings, with associated handling in its standard library.

The language supports low-level access to computer memory via pointers, procedure-like constructs in the form of functions returning void, and dynamic memory allocation through standard library functions. It includes the C preprocessor for macro definition, source-file inclusion, and conditional compilation. Modularity is supported by processing files separately, with visibility controlled through the static and extern attributes. Functionality is minimized in the core language, with relatively complex features such as I/O, string manipulation, and mathematical functions being provided through standard libraries. The resulting compiled code has relatively straightforward requirements of the underlying platform, making C desirable for operating and embedded systems.

Sign in to keep reading

7 more chapters are free with a Lably account.

More in Computing and information technology