A programming language is a machine-readable artificial language designed to express computations that can be performed by a machine, particularly a computer.... originally developed in 1972 by Dennis Ritchie
Dennis Ritchie
Dennis MacAlistair Ritchie is an American computer science notable for his influence on C and other programming languages, and on operating systems such as Multics and Unix.... at the Bell Telephone Laboratories to implement the Unix
Unix
Unix is a computer operating system originally developed in 1969 by a group of American Telephone & Telegraph employees at Bell Labs, including Ken Thompson , Dennis Ritchie, Douglas McIlroy, and Joe Ossanna.... operating system
Operating system
An operating system is an interface between hardware and applications; it is responsible for the management and coordination of activities and the sharing of the limited resources of the computer.... .
Although C was designed for writing architecturally independent system software
System software
System software is closely related to, but distinct from Operating System software. It is any computer software that provides the infrastructure over which programs can operate, i.e.... , it is also widely used for developing application software
Application software
Application software is any tool that functions and is operated by means of a computer, with the purpose of supporting or improving the software user 's work.... .
Worldwide, C is the first or second most popular language in terms of number of developer positions or publicly available code. It is widely used on many different software platforms, and there are few computer architecture
Computer architecture
Computer architecture in computer engineering is the conceptual design and fundamental operational structure of a computer system. It is a blueprint and functional description of requirements and design implementations for the various parts of a computer, focusing largely on the way by which the central processing unit performs internally an... s for which a C compiler
Compiler
A compiler is a computer program that transforms source code written in a programming language into another computer language . The most common reason for wanting to transform source code is to create an executable program.... does not exist.
Discussion
Ask a question about 'C (programming language)'
Start a new discussion about 'C (programming language)'
A programming language is a machine-readable artificial language designed to express computations that can be performed by a machine, particularly a computer.... originally developed in 1972 by Dennis Ritchie
Dennis Ritchie
Dennis MacAlistair Ritchie is an American computer science notable for his influence on C and other programming languages, and on operating systems such as Multics and Unix.... at the Bell Telephone Laboratories to implement the Unix
Unix
Unix is a computer operating system originally developed in 1969 by a group of American Telephone & Telegraph employees at Bell Labs, including Ken Thompson , Dennis Ritchie, Douglas McIlroy, and Joe Ossanna.... operating system
Operating system
An operating system is an interface between hardware and applications; it is responsible for the management and coordination of activities and the sharing of the limited resources of the computer.... .
Although C was designed for writing architecturally independent system software
System software
System software is closely related to, but distinct from Operating System software. It is any computer software that provides the infrastructure over which programs can operate, i.e.... , it is also widely used for developing application software
Application software
Application software is any tool that functions and is operated by means of a computer, with the purpose of supporting or improving the software user 's work.... .
Worldwide, C is the first or second most popular language in terms of number of developer positions or publicly available code. It is widely used on many different software platforms, and there are few computer architecture
Computer architecture
Computer architecture in computer engineering is the conceptual design and fundamental operational structure of a computer system. It is a blueprint and functional description of requirements and design implementations for the various parts of a computer, focusing largely on the way by which the central processing unit performs internally an... s for which a C compiler
Compiler
A compiler is a computer program that transforms source code written in a programming language into another computer language . The most common reason for wanting to transform source code is to create an executable program.... does not exist. C has greatly influenced many other popular programming languages, most notably C++
C++
C++ is a general-purpose programming language. It is regarded as a middle-level language, as it comprises a combination of both high-level programming language and low-level programming language language features.... , which originally began as an extension to C, and Java
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java .... and C# which borrow C lexical conventions and operators.
In computer science, imperative programming is a programming paradigm that describes computation in terms of statement s that change a program state .... (procedural
Procedural programming
Procedural programming can sometimes be used as a synonym for imperative programming , but can also refer to a programming paradigm based upon the concept of the procedure call.... ) systems implementation
System programming
System programming is the activity of programming system software. The primary distinguishing characteristic of systems programming when compared to application programming is that application programming aims to produce software which provides services to the user , whereas systems programming aims to produce software which provides service... language. It was designed to be compiled using a relatively straightforward compiler
Compiler
A compiler is a computer program that transforms source code written in a programming language into another computer language . The most common reason for wanting to transform source code is to create an executable program.... , to provide low-level access to memory, to provide language constructs that map efficiently to machine instructions, and to require minimal run-time support
Runtime
In computer science, runtime or run time describes the operation of a computer program, the duration of its execution, from beginning to termination .... . C was therefore useful for many applications that had formerly been coded in assembly language
Assembly language
An assembly language is a low-level language for programming computers. It implements a symbolic representation of the numeric machine codes and other constants needed to program a particular CPU architecture.... .
Despite its low-level capabilities, the language was designed to encourage machine-independent programming. A standards-compliant and portably
Porting
In computer science, porting is the process of adapting software so that an executable Computer program can be created for a computing environment that is different from the one for which it was originally designed .... written C program can be compiled for a very wide variety of computer platforms and operating systems with little or no change to its source code, while approaching highest performance. The language has become available on a very wide range of platforms, from embedded microcontroller
Microcontroller
A microcontroller is a small computer on a single integrated circuit consisting of a relatively simple CPU combined with support functions such as a crystal oscillator, timers, watchdog, serial and analog I/O etc.... s to supercomputer
Supercomputer
A supercomputer is a computer that is at the frontline of current processing capacity, particularly speed of calculation. Supercomputers introduced in the 1960s were designed primarily by Seymour Cray at Control Data Corporation , and led the market into the 1970s until Cray left to form his own company, Cray Research.... s.
Minimalism
C is designed to provide high-level abstracts for all the native features of a general-purpose CPU
Central processing unit
A central processing unit is an electronic circuit that can execute computer programs. This broad definition can easily be applied to many early computers that existed long before the term "CPU" ever came into widespread usage.... , while at the same time allowing modularization, structure, and code re-use. Features specific to a particular program's function (features that are not general to all platforms) are not included in the language or library definitions. However any such specific functions are implementable and accessible as external reusable libraries, in order to encourage module dissemination and re-use. C is somewhat strongly typed (emitting warnings or errors) but allows programmers to override types in the interests of flexibility, simplicity or performance; while being natural and well-defined in its interpretation of type overrides.
C's design is tied to its intended use as a portable systems implementation language. Consequently, it does not require run-time checks for conditions that would never occur in correct programs, it provides simple, direct access to any addressable object (for example, memory-mapped device control registers), and its source-code expressions can be translated in a straightforward manner to primitive machine operations in the executable code. Some early C compilers were comfortably implemented (as a few distinct passes communicating via intermediate files) on PDP-11
PDP-11
The PDP-11 was a series of 16-bit minicomputers sold by Digital Equipment Corporation from 1970 into the 1990s. Though not explicitly conceived as successor to DEC's PDP-8 computer in the Programmed Data Processor series of computers , the PDP-11 replaced the PDP-8 in many Real-time computing.... processors having only 16 address bits; however, C99 assumes a 512 KB minimum compilation platform.
Algol , known colloquially as the Demon Star, is a bright star in the constellation Perseus . It is one of the best known eclipsing binary, the first such star to be discovered, and also one of the first variable stars to be discovered.... tradition, C has facilities for structured programming
Structured programming
Structured programming can be seen as a subset or subdiscipline of procedural programming, one of the major programming paradigms. It is most famous for removing or reducing reliance on the GOTO Statement .... and allows lexical variable scope
Scope (programming)
In computer programming, scope is an enclosing context where values and expressions are associated. Various programming languages have various types of scopes.... and recursion
Recursion
Recursion, in mathematics and computer science, is a method of defining Function in which the function being defined is applied within its own definition.... , while a static type system
Type system
In computer science, a type system may be defined as "a tractable syntactic method for proving the absence of certain program behaviors by classifying phrases according to the kinds of values they compute.".... prevents many unintended operations. In C, all executable code is contained within functions
Subroutine
In computer science, a subroutine or subprogram is a portion of computer code within a larger computer program, which performs a specific task and is relatively independent of the remaining code.... . Function parameters
Parameter (computer science)
In computer programming, a parameter is a special kind of variable#In_computer_programming that refers to data that a subroutine receives to operate on.... are always passed by value. Pass-by-reference is achieved in C by explicitly passing pointer values. Heterogeneous aggregate data types (struct) allow related data elements to be combined and manipulated as a unit. C program source text is free-format, using the semicolon as a statement terminator (not a delimiter).
C also exhibits the following more specific characteristics:
In computer science, weak typing is a property attributed to the type systems of some programming languages. It is the opposite of strong typing, and consequently the term weak typing has as many different meanings as strong typing does .... ; for instance, characters can be used as integers
Computer memory is usually meant to refer to the semiconductor technology that is used to store information in Electronics devices. Current primary computer memory makes use of integrated circuits consisting of silicon-based transistors.... by converting machine addresses to typed pointers
In computer science, polymorphism is a programming language feature that allows values of different data types to be handled using a uniform interface....
In computer science, an array is a data structure consisting of a group of element s that are accessed by index . In most programming languages each element has the same data type and the array occupies a contiguous area of computer memory.... indexing as a secondary notion, defined in terms of pointer arithmetic
The C preprocessor is the preprocessor for the C . In many C implementations, it is a separate computer program invoked by the compiler as the first part of translation.... for macro definition, source code
Source code
In computer science, source code is any collection of statements or declarations written in some human-readable computer programming language.... file inclusion, and conditional compilation
In computing, input/output, or I/O, refers to the communication between an information processing system , and the outside world ? possibly a human, or another information processing system.... , string
String (computer science)
In computer programming and some branches of mathematics, a string is an ordered sequence of symbols. These symbols are chosen from a predetermined set or alphabet.... manipulation, and mathematical functions consistently delegated to library routines
Library (computer science)
In computer science, a library is a collection of subroutines or Class used to develop software. Libraries contain code and data that provide services to independent programs....
In computer programming, a keyword is a word or identifier that has a particular meaning to the programming language. The meaning of keywords ? and, indeed, the meaning of the notion of keyword ? differs widely from language to language.... (originally 32, now 37 in C99)
A lexical structure that resembles B more than ALGOL
Algol
Algol , known colloquially as the Demon Star, is a bright star in the constellation Perseus . It is one of the best known eclipsing binary, the first such star to be discovered, and also one of the first variable stars to be discovered.... , for example
Algol , known colloquially as the Demon Star, is a bright star in the constellation Perseus . It is one of the best known eclipsing binary, the first such star to be discovered, and also one of the first variable stars to be discovered.... 's begin ... end
the equal-sign is for assignment (copying), much like Fortran
Fortran
Fortran is a general-purpose programming language, procedural programming language, imperative programming language programming language that is especially suited to numerical analysis and scientific computing....
two consecutive equal-signs are to test for equality (compare to .EQ. in Fortran
Fortran
Fortran is a general-purpose programming language, procedural programming language, imperative programming language programming language that is especially suited to numerical analysis and scientific computing.... or the equal-sign in BASIC
BASIC
In computer programming, BASIC is a family of high-level programming languages. The Dartmouth BASIC was designed in 1964 by John George Kemeny and Thomas Eugene Kurtz at Dartmouth College in New Hampshire, United States to provide computer access to non-science students.... )
Algol , known colloquially as the Demon Star, is a bright star in the constellation Perseus . It is one of the best known eclipsing binary, the first such star to be discovered, and also one of the first variable stars to be discovered.... 's and and or (these are semantically distinct from the bit-wise
Bitwise operation
In computer programming, a bitwise operation operates on one or two bit patterns or Binary numeral system at the level of their individual bits.... operators & and | because they will never evaluate the right operand if the result can be determined from the left alone (short-circuit evaluation)).
a large number of compound operators, such as +=, ++, ......
Absent features
The relatively low-level nature of the language affords the programmer close control over what the computer does, while allowing special tailoring and aggressive optimization for a particular platform. This allows the code to run efficiently on very limited hardware, such as embedded systems.
C does not have some features that are available in some other programming languages:
No assignment of arrays or strings (copying can be done via standard functions; assignment of objects having struct or union type is supported)
In computer science, garbage collection is a form of automatic memory management. The garbage collector, or just collector, attempts to reclaim garbage , or memory used by Object that will never be accessed or mutated again by the Application software....
In computer programming, bounds checking is any method of detecting whether a variable is within some bounds before its use. It is particularly relevant to a variable used as an index into an array to ensure its value lies within the bounds of the array.... of arrays
In computer science, array programming languages generalize operations on scalar s to apply transparently to vector s, matrix , and higher dimensional arrays....
In computer science, the term range may refer to one of two things:# The maximum and minimum values that may be stored in a variable.# The upper and lower bounds of an array.... , such as the A..B notation used in several languages
In computer science, the Boolean algebra datatype, sometimes called the logical datatype, is a primitive datatype having one of two values: Truth value and false.... : zero/nonzero is used instead
In computer science, a closure is a function that is evaluated in an environment containing one or more bound variables. When called, the function can access these variables.... s or functions as parameters (only function and variable pointers)
In computer science, a generator is a special subroutine that can be used to control the iteration behaviour of a control flow#Loops. A generator is very similar to a function that returns an array, in that a generator has parameters, can be called, and generates a sequence of values.... s or coroutine
Coroutine
In computer science, coroutines are program components that generalize subroutines to allow multiple entry points for suspending and resuming of execution at certain locations.... s; intra-thread control flow consists of nested function calls, except for the use of the longjmp or setcontext
Setcontext
setcontext is one of a family of C library Subroutines used for context control. The setcontext family allows the implementation in C of advanced control flow design patterns such as iterators, fiber , and coroutines.... library functions
Exception handling is a programming language construct or computer hardware mechanism designed to handle the occurrence of exceptions - special conditions that change the normal flow of execution.... ; standard library functions signify error conditions with the global errno variable and/or special return values
Only rudimentary support for modular programming
No compile-time polymorphism in the form of function or operator
Operator
In mathematics, an operator is a function which operates on another function. Often, an "operator" is a function which acts on functions to produce other functions ; or it may be a generalization of such a function, as in linear algebra, where some of the terminology reflects the origin of the subject in operations on the functions which ar... overloading
Method overloading
Method overloading is a feature found in various programming languages such as Ada , C Sharp , C++, D and Java that allows the creation of several subprograms with the same name which differ from each other in terms of the type of the input and the type of the output of the function....
Generic programming is a style of computer programming in which algorithms are written in terms of to-be-specified-later types that are then instantiated when needed for specific types provided as parameters and was pioneered by Ada which appeared in 1983....
Object-oriented programming is a programming paradigm that uses "Object_" and their interactions to design applications and computer programs.... with regard to polymorphism
Polymorphism in object-oriented programming
In simple terms, polymorphism is the ability of one type, A, to appear as and be used like another type, B. In strongly typed languages, this usually means that type A somehow derives from type B, or type A implements an interface that represents type B.... and inheritance
Inheritance (computer science)
In object-oriented programming, inheritance is a way to form new class es using classes that have already been defined. The inheritance concept was invented in 1967 for Simula....
Information hiding in computer science is the principle of hiding of design decisions in a computer program that are most likely to change, thus protecting other parts of the program from change if the design decision is changed....
No native support for multithreading and networking
Computer graphics are graphics created by computers and, more generally, the representation and manipulation of pictorial data by a computer.... and several other application programming needs
A number of these features are available as extensions in some compilers, or can be supplied by third-party libraries, or can be simulated by adopting certain coding disciplines.
Undefined behavior
Many operations in C that have undefined behavior are not required to be diagnosed at compile time
Compile time
In computer science, compile time refers to either the operations performed by a compiler , programming language requirements that must be met by source code for it to be successfully compiled , or properties of the program that can be reasoned about at compile time.... . In the case of C, "undefined behavior" means that the exact behavior which arises is not specified by the standard, and exactly what will happen does not have to be documented by the C implementation. A famous, although misleading, expression in the newsgroup
Newsgroup
A newsgroup is a repository usually within the Usenet system, for messages Posting style from many users in different locations. The term may be confusing to some, because it is usually a discussion group.... s [news:comp.std.c comp.std.c] and [news:comp.lang.c comp.lang.c] is that the program could cause "demons to fly out of your nose". Sometimes in practice what happens for an instance of undefined behavior is a bug
Software bug
A software bug is an error, flaw, mistake, failure, or fault in a computer program that prevents it from behaving as intended . Most bugs arise from mistakes and errors made by people in either a program's source code or its software architecture, and a few are caused by compilers producing incorrect code.... that is hard to track down and which may corrupt the contents of memory. Sometimes a particular compiler generates reasonable and well-behaved actions that are completely different from those that would be obtained using a different C compiler. The reason some behavior has been left undefined is to allow compilers for a wide variety of instruction set
Instruction set
An instruction set is a list of all the instruction , and all their variations, that a processor can execute.Instructions include:* Arithmetic such as add and subtract... architectures to generate more efficient executable code for well-defined behavior, which was deemed important for C's primary role as a systems implementation language; thus C makes it the programmer's responsibility to avoid undefined behavior. Examples of undefined behavior are:
accessing outside the bounds of an array
overflowing a signed integer
reaching the end of a non-void function without finding a return statement, when the return value is used
reading the value of a variable before initializing it
These operations are all programming errors that could occur using many programming languages; C draws criticism because its standard explicitly identifies numerous cases of undefined behavior, including some where the behavior could have been made well defined, and does not specify any run-time error handling mechanism.
fflush is a C programming language Subroutine belonging to the ANSI C standard library, and included in the file stdio.h. Its purpose is deliver, to the host environment, unwritten data present in an output or update stream, or multiple streams, to be actually written to those streams' underlying file or device.... on a stream opened for input is an example of a different kind of undefined behavior, not necessarily a programming error but a case for which some conforming implementations may provide well-defined, useful semantics (in this example, presumably discarding input through the next new-line) as an allowed extension. Use of such nonstandard extensions generally limits software portability
Software portability
Portability is one of the key concepts of High-level programming language. Portability is the software codebase feature to be able to reuse the existing code instead of creating new code when moving software from an environment to another.... .
AT&T Inc. is the largest US provider of both local and long distance telephone services, and Digital subscriber line Internet access. AT&T is the second largest provider of wireless service in the United States, with over 77 million wireless customers, and more than 150 million total customers.... Bell Labs
Bell Labs
Bell Laboratories is the research organization of Alcatel-Lucent and previously of the American Telephone & Telegraph Company .Bell Laboratories has had its headquarters at Berkeley Heights, New Jersey, and it has research and development facilities throughout the world.... between 1969 and 1973; according to Ritchie, the most creative period occurred in 1972. It was named "C" because many of its features were derived from an earlier language called "B", which according to Ken Thompson was a stripped-down version of the BCPL
BCPL
BCPL is a computer programming language designed by Martin Richards of the University of Cambridge in 1966.... programming language.
The origin of C is closely tied to the development of the Unix
Unix
Unix is a computer operating system originally developed in 1969 by a group of American Telephone & Telegraph employees at Bell Labs, including Ken Thompson , Dennis Ritchie, Douglas McIlroy, and Joe Ossanna.... operating system, originally implemented in assembly language on a PDP-7
PDP-7
The Digital Equipment Corporation PDP-7 is a minicomputer produced by Digital Equipment Corporation. Introduced in 1965, the first to use their Flip Chip technology, with a cost of only $72,000 USD, it was cheap but powerful.... by Ritchie and Thompson, incorporating several ideas from colleagues. Eventually they decided to port the operating system to a PDP-11
PDP-11
The PDP-11 was a series of 16-bit minicomputers sold by Digital Equipment Corporation from 1970 into the 1990s. Though not explicitly conceived as successor to DEC's PDP-8 computer in the Programmed Data Processor series of computers , the PDP-11 replaced the PDP-8 in many Real-time computing.... . B's lack of functionality to take advantage of some of the PDP-11's features, notably byte
Byte
A byte is a basic unit of measurement of Computer storage in computer science. In many computer architectures it is a Byte addressing memory address space.... addressability, led to the development of an early version of the C programming language.
The original PDP-11 version of the Unix system was developed in assembly language. By 1973, with the addition of struct types, the C language had become powerful enough that most of the Unix
Unix
Unix is a computer operating system originally developed in 1969 by a group of American Telephone & Telegraph employees at Bell Labs, including Ken Thompson , Dennis Ritchie, Douglas McIlroy, and Joe Ossanna.... kernel was rewritten in C. This was one of the first operating system kernels implemented in a language other than assembly. (Earlier instances include the Multics
Multics
Multics was an extremely influential early time-sharing operating system. The project was started in 1964. The last known running Multics installation was shut down on October 30, 2000.... system (written in PL/I
PL/I
PL/I is an imperative programming computer programming programming language designed for scientific, engineering, and business applications. It is one of the most feature-rich programming languages and one of the very first in the highly-feature-rich category.... ), and MCP (Master Control Program
MCP (Burroughs Large Systems)
The MCP is the Proprietary software operating system of the Burroughs large systems including the Unisys Clearpath/MCP systems. Originally written in 1961 in ESPOL , which itself was an extension of Burroughs Corporation Extended ALGOL, in the 1970s it was converted to NEWP, a better structured, more robust, and more secure form of ESP... ) for the Burroughs B5000 written in ALGOL
Algol
Algol , known colloquially as the Demon Star, is a bright star in the constellation Perseus . It is one of the best known eclipsing binary, the first such star to be discovered, and also one of the first variable stars to be discovered.... in 1961.)
Brian Wilson Kernighan , is a computer scientist who worked at Bell Labs alongside Unix creators Ken Thompson and Dennis Ritchie and contributed greatly to Unix and its school of thought.... and Dennis Ritchie
Dennis Ritchie
Dennis MacAlistair Ritchie is an American computer science notable for his influence on C and other programming languages, and on operating systems such as Multics and Unix.... published the first edition of The C Programming Language
The C Programming Language (book)
The C Programming Language is a well-known computer science book written by Brian Kernighan and Dennis Ritchie, the latter of whom originally designed and implemented the language .... . This book, known to C programmers as "K&R", served for many years as an informal specification of the language. The version of C that it describes is commonly referred to as "K&R C". The second edition of the book covers the later ANSI C
ANSI C
ANSI C is the standard published by the American National Standards Institute for the C . Software developers writing in C are encouraged to conform to the requirements in the document, as it encourages easily porting code.... standard.
K&R introduced several language features:
standard I/O library
long int data type
unsigned int data type
compound assignment operators =op were changed to op= to remove the semantic ambiguity created by the construct i=-10, which had been interpreted as i =- 10 instead of the possibly intended i = -10
Even after the publication of the 1989 C standard, for many years K&R C was still considered the "lowest common denominator" to which C programmers restricted themselves when maximum portability was desired, since many older compilers were still in use, and because carefully written K&R C code can be legal Standard C as well.
In early versions of C, only functions that returned a non-integer value needed to be declared if used before the function definition; a function used without any previous declaration was assumed to return an integer, if its value was used.
For example:
long int SomeFunction;
/* int OtherFunction; */
/* int */ CallingFunction
All the above commented-out int declarations could be omitted in K&R C.
Since K&R function declarations did not include any information about function arguments, function parameter type checks were not performed, although some compilers would issue a warning message if a local function was called with the wrong number of arguments, or if multiple calls to an external function used different numbers or types of arguments. Separate tools such as Unix's lint
Lint programming tool
In computer programming, lint was the name originally given to a particular program that flagged suspicious and non-portable constructs in C source code.... utility were developed that (among other things) could check for consistency of function use across multiple source files.
In the years following the publication of K&R C, several unofficial features were added to the language, supported by compilers from AT&T and some other vendors. These included:
The void type, in several Curly bracket programming language, is the type theory for the result of a function that produces no direct result. Usually such functions are called for their Side effect , much like subroutines in Visual Basic and procedures in Pascal programming language.... functions
In computer science, a union is a data structure that stores one of several types of data at a single location. There are only two safe ways of accessing a union object.... types (rather than pointers)
In computer science the assignment statement sets or re-sets the Value stored in the storage location denoted by a variable name. In most imperative programming computer programming languages the assignment statement is one of the basic Statement s.... for struct data types
In computer programming, an enumerated type is a data type consisting of a set of named constants called enumerators. The act of creating an enumerated type defines an enumeration.... s
The large number of extensions and lack of agreement on a standard library
C standard library
The C standard library consists of a set of sections of the ISO C standard which describe a collection of header files and library routines used to implement common operations, such as input/output and character string handling, in the C .... , together with the language popularity and the fact that not even the Unix compilers precisely implemented the K&R specification, led to the necessity of standardization.
ANSI C and ISO C
During the late 1970s and 1980s, versions of C were implemented for a wide variety of mainframe computer
Mainframe computer
Mainframes are computers used mainly by large organizations for critical applications, typically bulk data processing such as census, industry and consumer statistics, Enterprise Resource Planning, and financial transaction processing.... s, minicomputer
Minicomputer
A minicomputer is a class of multi-user computers that lies in the middle range of the computing spectrum, in between the largest multi-user systems and the smallest single-user systems .... s, and microcomputer
Microcomputer
A microcomputer is a computer with a microprocessor as its central processing unit. Another general characteristic of these computers is that they occupy physically small amounts of space when compared to mainframe computer and minicomputers.... s, including the IBM PC
IBM PC
The IBM Personal Computer, commonly known as the IBM PC, is the original version and progenitor of the IBM PC compatible hardware platform .... , as its popularity began to increase significantly.
The American National Standards Institute or ANSI is a private non-profit organization that oversees the development of voluntary consensus standards for products, services, processes, systems, and personnel in the United States.... (ANSI) formed a committee, X3J11, to establish a standard specification of C. In 1989, the standard was ratified as ANSI X3.159-1989 "Programming Language C." This version of the language is often referred to as ANSI C
ANSI C
ANSI C is the standard published by the American National Standards Institute for the C . Software developers writing in C are encouraged to conform to the requirements in the document, as it encourages easily porting code.... , Standard C, or sometimes C89.
The International Organization for Standardization , widely known as ISO , is an international standard-setting body composed of representatives from various national standards organizations.... (ISO) as ISO/IEC 9899:1990, which is sometimes called C90. Therefore, the terms "C89" and "C90" refer to the same programming language.
ANSI, like other national standards bodies, no longer develops the C standard independently, but defers to the ISO C standard. National adoption of updates to the international standard typically occurs within a year of ISO publication.
One of the aims of the C standardization process was to produce a superset
SuperSet
SuperSet Software was a group founded by friends and former Eyring Research Institute co-workers Drew Major, Dale Neibaur, Kyle Powell and later joined by Mark Hurst.... of K&R C, incorporating many of the unofficial features subsequently introduced. The standards committee also included several additional features such as function prototype
Function prototype
A function prototype in C or C++ is a declaration of a subroutine that omits the function body but does specify the function's name, arity, argument datatypes and return type.... s (borrowed from C++), void pointers, support for international character sets
Character encoding
A character encoding system consists of a code that pairs a sequence of character from a given character set with something else, such as a sequence of natural numbers, octet or electrical pulses, in order to facilitate the transmission of data through telecommunication networks and/or Computer data storage of Character in compute... and locale
Locale
In computing, locale is a set of parameters that defines the user's language, country and any special variant preferences that the user wants to see in their user interface.... s, and preprocessor enhancements. The syntax for parameter declarations was also augmented to include the style used in C++, although the K&R interface continued to be permitted, for compatibility with existing source code.
C89 is supported by current C compilers, and most C code being written nowadays is based on it. Any program written only in Standard C and without any hardware-dependent assumptions will run correctly on any platform with a conforming C implementation, within its resource limits. Without such precautions, programs may compile only on a certain platform or with a particular compiler, due, for example, to the use of non-standard libraries, such as GUI
Graphical user interface
A graphical user interface is a type of user interface which allows people to human-computer interaction such as computers; hand-held devices such as MP3 Players, Portable Media Players or Gaming devices; household appliances and office equipment.... libraries, or to a reliance on compiler- or platform-specific attributes such as the exact size of data types and byte endianness
Endianness
In computing, endianness is the byte ordering used to represent some kind of data. Typical cases are the order in which integer values are stored as bytes in computer memory and the transmission order over a network or other medium.... .
In cases where code must be compilable by either standard-conforming or K&R C-based compilers, the __STDC__ macro can be used to split the code into Standard and K&R sections to take advantage of features available only in Standard C.
C99
After the ANSI/ISO standardization process, the C language specification remained relatively static for some time, whereas C++
C++
C++ is a general-purpose programming language. It is regarded as a middle-level language, as it comprises a combination of both high-level programming language and low-level programming language language features.... continued to evolve, largely during its own standardization effort. In 1995 Normative Amendment 1 to the 1990 C standard was published, to correct some details and to add more extensive support for international character sets. The C standard was further revised in the late 1990s, leading to the publication of ISO/IEC 9899:1999 in 1999, which is commonly referred to as "C99
C99
C99 is a modern dialect of the C programming language.... ." It has since been amended three times by Technical Corrigenda. The international C standard is maintained by the working group
Working Group
Working Group can mean:*Working group, an interdisciplinary group of researchers; or*Working Group , kennel club designation for certain purebred dog breeds; or... ISO/IEC JTC1/SC22
SC22
SC22, or to give it its full title JTC1/SC22, is the ISO subcommittee for programming languages, their environments and system software interfaces.... /WG14.
C99 introduced several new features, including inline function
Inline function
In computer science, an inline function is a programming language construct used to suggest to a compiler that a particular function be subjected to inline expansion; that is, it suggests that the compiler insert the complete body of the function in every context where that function is used.... s, several new data type
Data type
A data type in programming languages is an attribute of a data which tells the computer something about the kind of data it is. This involves setting constraints on the datum, such as what values it can take and what operations may be performed upon it.... s (including long long int and a complex type to represent complex number
Complex number
In mathematics, the complex numbers are an extension of the real numbers obtained by adjoining an imaginary unit, denoted i, which satisfies:... s), variable-length array
Variable-length array
In programming, a variable length array is an array data structure of automatic variable whose length is determined at run time .Programming languages that support VLAs include APL , COBOL, and C .... s, support for variadic macro
Variadic macro
A variadic macro is a feature of the C preprocessor whereby a Macro may be declared to accept a varying number of Parameter .Variable-argument macros were introduced in the ISO/IEC 9899:1999 revision of the C Programming Language standard in 1999.... s (macros of variable arity
Arity
In logic, mathematics, and computer science, the arity of a function or operation is the number of arguments or operands that the function takes. The arity of a relation is the number of domains in the corresponding Cartesian product.... ) and support for one-line comments beginning with //, as in BCPL
BCPL
BCPL is a computer programming language designed by Martin Richards of the University of Cambridge in 1966.... or C++. Many of these had already been implemented as extensions in several C compilers.
C99 is for the most part backward compatible with C90, but is stricter in some ways; in particular, a declaration that lacks a type specifier no longer has int implicitly assumed. A standard macro __STDC_VERSION__ is defined with value 199901L to indicate that C99 support is available. GCC
GNU Compiler Collection
The GNU Compiler Collection is a compiler system produced by the GNU Project supporting various programming languages. GCC is a key component of the GNU toolchain.... , Sun Studio
Sun Studio (software)
The Sun Studio compiler suite is Sun Microsystems' flagship software development product for Solaris and Linux. Sun Studio software delivers optimizing C, C++, and Fortran compilers, libraries, and performance analysis, and debugging tools for the Solaris OS on SPARC, and both Solaris and Linux on x86/x64 platforms, including the latest mult... and other C compilers now support many or all of the new features of C99.
As of 2007, work has begun in anticipation of another revision of the C standard, informally called "C1x". The C standards committee has adopted guidelines to limit the adoption of new features that have not been tested by existing implementations.
System programming is the activity of programming system software. The primary distinguishing characteristic of systems programming when compared to application programming is that application programming aims to produce software which provides services to the user , whereas systems programming aims to produce software which provides service... ", including implementing operating system
Operating system
An operating system is an interface between hardware and applications; it is responsible for the management and coordination of activities and the sharing of the limited resources of the computer.... s and embedded system
Embedded system
An embedded system is a special-purpose computer system designed to perform one or a few dedicated functions, often with real-time computing constraints.... applications, due to a combination of desirable characteristics such as code portability and efficiency, ability to access specific hardware addresses, ability to "pun"
Type punning
__FORCETOC__In computer science, type punning is a common term for any programming technique that subverts or circumvents the type system of a programming language in order to achieve an effect that would be difficult or impossible to achieve within the bounds of the formal language.... types to match externally imposed data access requirements, and low runtime
Runtime
In computer science, runtime or run time describes the operation of a computer program, the duration of its execution, from beginning to termination .... demand on system resources.
One consequence of C's wide acceptance and efficiency is that C is used for other programs that are not directly used by end-users (compilers, libraries, interpreters, etc).
In computer science, an intermediate language is the language of an abstract machine designed to aid in the analysis of computer programs. The term comes from their use in compilers, where a compiler first translates the source code of a program into a form more suitable for code-improving transformations, as an intermediate step before gener... by implementations of other languages. This approach may be used for convenience (by using C as an intermediate language, it is not necessary to develop machine-specific code generators; ). Some compilers which use C this way are BitCC
BitC
BitC is a programming language currently being developed by researchers at the Johns Hopkins University and , as part of the Coyotos project. The language has two primary objectives:... , Gambit
Gambit (Scheme implementation)
Gambit, also called Gambit-C, is a free software Scheme implementation, consisting of a Scheme Interpreter , and a compiler which compiles Scheme to C .... , the Glasgow Haskell Compiler
Glasgow Haskell Compiler
The Glorious Glasgow Haskell Compilation System, more commonly known as the Glasgow Haskell Compiler or GHC, is an open source Machine language compiler for the functional programming Computer programming Programming language Haskell .... , Squeak
Squeak
The Squeak programming language is a Smalltalk implementation, derived directly from Smalltalk-80 by a group at Apple Computer that included some of the original Smalltalk-80 developers.... , and valac
Vala (programming language)
Vala is a programming language that tries to bring modern language features to C , without additional runtime requirements and with little overhead, by targeting the GObject object system.... .
Unfortunately, C was designed as a programming language, not as a compiler target language, and is thus less than ideal for use as an intermediate language. This has led to development of C-based intermediate languages such as C--
C--
C-- is a C -like programming language. Its creators, functional programming researchers Simon Peyton Jones and Norman Ramsey , designed it to be generated mainly by compilers for very high-level languages rather than written by human programmers.... .
The end-user is a concept in software engineering, referring to an abstraction of the group of persons who will ultimately operate a piece of software .... applications. Although as applications became larger, much of that development shifted to other languages.
Syntax
Unlike languages such as FORTRAN 77, C source code is free-form
Free-form language
In computer programming, a free-form language is a programming language in which the positioning of character on the page in program text is not significant.... which allows arbitrary use of whitespace to format code, rather than column-based or text-line-based restrictions. Comments may appear either between the delimiters /* and */, or (in C99) following // until the end of the line.
Each source file contains declarations and function definitions. Function definitions, in turn, contain declarations and statements. Declarations either define new types using keywords such as struct, union, and enum, or assign types to and perhaps reserve storage for new variables, usually by writing the type followed by the variable name. Keywords such as char and int specify built-in types. Sections of code are enclosed in braces (, sometimes called "curly brackets") to limit the scope of declarations and to act as a single statement for control structures.
As an imperative language, C uses statements to specify actions. The most common statement is an expression statement, consisting of an expression to be evaluated, followed by a semicolon; as a side effect of the evaluation, functions may be called and variables may be assigned
Assignment (computer science)
In computer science the assignment statement sets or re-sets the Value stored in the storage location denoted by a variable name. In most imperative programming computer programming languages the assignment statement is one of the basic Statement s.... new values. To modify the normal sequential execution of statements, C provides several control-flow statements identified by reserved keywords. Structured programming
Structured programming
Structured programming can be seen as a subset or subdiscipline of procedural programming, one of the major programming paradigms. It is most famous for removing or reducing reliance on the GOTO Statement .... is supported by if(-else) conditional execution and by do-while, while, and for iterative execution (looping). The for statement has separate initialization, testing, and reinitialization expressions, any or all of which can be omitted. break and continue can be used to leave the innermost enclosing loop statement or skip to its reinitialization. There is also a non-structured goto
GOTO
GOTO is a statement found in many computer programming languages. It is a combination of the English words wiktionary:go and wiktionary:to.... statement which branches directly to the designated label
Label (programming language)
A label in a programming language is a sequence of characters that identifies a location within source code. In most languages labels take the form of an identifier, often followed by a punctuation .... within the function. switch selects a case to be executed based on the value of an integer expression.
Expressions can use a variety of built-in operators (see below) and may contain function calls. The order in which operands to most operators, as well as the arguments to functions, are evaluated is unspecified; the evaluations may even be interleaved. However, all side effects (including storage to variables) will occur before the next "sequence point
Sequence point
A sequence point in imperative programming defines any point in a computer program's execution at which it is guaranteed that all side effect s of previous evaluations will have been performed, and no side effects from subsequent evaluations have yet been performed.... "; sequence points include the end of each expression statement and the entry to and return from each function call. This permits a high degree of object code optimization by the compiler, but requires C programmers to exert more care to obtain reliable results than is needed for other programming languages.
Although mimicked by many languages because of its widespread familiarity, C's syntax has often been criticized. For example, Kernighan and Ritchie say in the second edition of The C Programming Language, "C, like any other language, has its blemishes. Some of the operators have the wrong precedence; some parts of the syntax could be better."
Some specific problems worth noting are:
Not checking number and types of arguments when the function declaration has an empty parameter list. (This provides backward compatibility
Backward compatibility
In technology, for example in telecommunications and computing, a device or technology is said to be backwards compatible if it allows input generated by older devices.... with K&R C
The C Programming Language (book)
The C Programming Language is a well-known computer science book written by Brian Kernighan and Dennis Ritchie, the latter of whom originally designed and implemented the language .... , which lacked prototypes.)
Some questionable choices of operator precedence, as mentioned by Kernighan and Ritchie above, such as
binding more tightly than & and | in expressions like x & 1
0.
The use of the = operator, used in mathematics for equality, to indicate assignment, following the precedent of Fortran
Fortran
Fortran is a general-purpose programming language, procedural programming language, imperative programming language programming language that is especially suited to numerical analysis and scientific computing.... , PL/I
PL/I
PL/I is an imperative programming computer programming programming language designed for scientific, engineering, and business applications. It is one of the most feature-rich programming languages and one of the very first in the highly-feature-rich category.... , and BASIC
BASIC
In computer programming, BASIC is a family of high-level programming languages. The Dartmouth BASIC was designed in 1964 by John George Kemeny and Thomas Eugene Kurtz at Dartmouth College in New Hampshire, United States to provide computer access to non-science students.... , but unlike ALGOL
Algol
Algol , known colloquially as the Demon Star, is a bright star in the constellation Perseus . It is one of the best known eclipsing binary, the first such star to be discovered, and also one of the first variable stars to be discovered.... and its derivatives. Ritchie made this syntax design decision consciously, based primarily on the argument that assignment occurs more often than comparison.
Similarity of the assignment and equality operators (= and
), making it easy to accidentally substitute one for the other. C's weak type system permits each to be used in the context of the other without a compilation error (although some compilers produce warnings). For example, the conditional expression in if (a=b) is only true if a is not zero after the assignment.
Infix notation is the common arithmetic and logical formula notation, in which operators are written infix-style between the operands they act on .... operators for complex objects, particularly for string operations, making programs which rely heavily on these operations (implemented as functions instead) somewhat difficult to read.
A declaration syntax that some find unintuitive, particularly for function pointer
Function pointer
A function pointer is a type of pointer in C , C++, D programming language, and other C-like programming languages. When Dereference operator, a function pointer invokes a subroutine, passing it zero or more arguments just like a normal function.... s. (Ritchie's idea was to declare identifiers in contexts resembling their use: "declaration reflects use".)
Programming languages generally support a set of operators that are similar to operator. A language may contain a fixed number of built-in operators or it may allow the creation of programmer-defined operators .... , which are symbols used within an expression
Expression (programming)
An expression in a programming language is a combination of value s, variables, operator s, and function s that are interpreted according to the particular Order of operations and of association for a particular programming language, which computes and then produces another value.... to specify the manipulations to be performed while evaluating that expression. C has operators for:
Arithmetic or arithmetics is the oldest and most elementary branch of mathematics, used by almost everyone, for tasks ranging from simple day-to-day counting to advanced science and business calculations.... (+
Addition
Addition is the mathematics process of putting things together. The plus sign "+" means that numbers are added together. For example, in the picture on the right, there are 3 + 2 apples?meaning three apples and two other apples?which is the same as five apples, since 3 + 2 = 5.... , -
Subtraction
Subtraction is one of the four basic arithmetic operations; it is the inverse of addition, meaning that if we start with any number and add any number and then subtract the same number we added, we return to the number we started with.... , *
Multiplication
Multiplication is the Operation of scaling one number by another. It is one of the four basic operations in elementary arithmetic .Multiplication is defined for Natural number in terms of repeated addition; for example, 4 multiplied by 3 can be calculated by adding 3 copies of 4 together:... , /
Division (mathematics)
In mathematics, especially in elementary arithmetic, division is an arithmetic operation which is the inverse of multiplication.Specifically, if c times b equals a, written:... , %
Modulo operation
In computing, the modulo operation finds the remainder of division of one number by another.Given two numbers, and , amodulon is the remainder, on division of a by n.... )
equality testing (
Equality (mathematics)
Equality is the paradigmatic example of the more general concept of equivalence relations on a set: those binary relations which are reflexive relation, symmetric relation, and transitive relation.... , !=)
Boolean algebra is a logical calculus of logical values, developed by George Boole in the late 1830s. It resembles the algebra of real numbers as taught in high school, but with the numeric operations of multiplication xy, addition x + y, and negation −x replaced by the respective logical operations of conjun... (!, &&, ||)
An increment is an increase of some amount, either fixed or variable. For example one's salary may have a fixed annual increment or one based on a percentage of its current value.... and decrement (++, --)
Commonly referred to as the conditional operator, ?: is a ternary operator that is part of the syntax for a basic conditional statement in several programming languages including C , C++, JavaScript, Objective-C, C Sharp , D programming language, Java , ECMAScript, Perl, PHP, Tcl, Ruby programming language, and Verilog.... )
In computer science, a record type or struct is a type whose values are records, i.e. aggregates of several items of possibly different types.... (., ->)
In computer science, type conversion or typecasting refers to changing an entity of one data type into another. This is done to take advantage of certain features of type hierarchies.... ()
In the programming languages C programming language and C++, the unary operator 'sizeof' is used to calculate the sizes of Data_type. sizeof can be applied to all datatypes, be they primitive types such as the Integer and IEEE floating-point standard types defined in the language, Data pointer, or the compound datatypes defined... )
A sequence point in imperative programming defines any point in a computer program's execution at which it is guaranteed that all side effect s of previous evaluations will have been performed, and no side effects from subsequent evaluations have yet been performed.... (,
Comma operator
In the C programming language, C++, and other related programming languages, the comma operator is a binary operator that evaluates its first operand and discards the result, it then evaluates the second operand and returns this value .... )
In algebra and computer programming, when a number or expression is both preceded and followed by an operator such as minus or multiplication, a rule is needed to specify which operator should be applied first; this rule is known as a precedence rule, or more informally order of operation.... ()
In formal language theory, grammars, also called formal grammars or generative grammars, are a formalism used to describe formal languages – i.e.... , specified by the C standard.
"Hello, world" example
The "hello, world" example which appeared in the first edition of K&R
The C Programming Language (book)
The C Programming Language is a well-known computer science book written by Brian Kernighan and Dennis Ritchie, the latter of whom originally designed and implemented the language .... has become the model for an introductory program in most programming textbooks, regardless of programming language. The program prints "hello, world" to the standard output, which is usually a terminal or screen display. A standard-conforming "hello, world" program is:
include
int main(void)
The first line of the program contains a preprocessing directive, indicated by #include. This causes the preprocessor — the first tool to examine source code as it is compiled — to substitute the line with the entire text of the stdio.h standard header, which contains declarations for standard input and output functions such as printf. The angle brackets surrounding stdio.h indicate that stdio.h is located using a search strategy that prefers standard headers to other headers having the same name. Double quotes may also be used to include local or project-specific header files.
The next line indicates that a function named main is being defined. The main
Main function (programming)
In some programming languages, the main function is where a program starts execution.It is generally the first user-written function run when a program starts , though some languages can execute user-written functions before main runs.... function serves a special purpose in C programs: The run-time environment calls the main function to begin program execution. The type specifier int indicates that the return value, the value that is returned to the invoker (in this case the run-time environment) as a result of evaluating the main function, is an integer. The keyword void as a parameter list indicates that the main function takes no arguments.
The opening curly brace indicates the beginning of the definition of the main function.
The next line calls (executes the code for) a function named printf
Printf
The class of printf functions is a class of function , typically associated with curly bracket programming languages, that accept a string parameter which specifies a method for rendering a number of other parameters into a string.... , which was declared in stdio.h and is supplied from a system library
Library (computer science)
In computer science, a library is a collection of subroutines or Class used to develop software. Libraries contain code and data that provide services to independent programs.... . In this call, the printf function is passed (provided with) a single argument, the address of the first character in the string literal "hello, world\n". The string literal is an unnamed array
Array
In computer science, an array is a data structure consisting of a group of element s that are accessed by index . In most programming languages each element has the same data type and the array occupies a contiguous area of computer memory.... with elements of type char, set up automatically by the compiler with a final 0-valued character to mark the end of the array (printf needs to know this). The \n is an escape sequence that C translates to a newline
Newline
In computing, a newline is a special character or sequence of characters signifying the end of a line of text. The name comes from the fact that the next character after the newline will appear on a new line?that is, on the next line below the text, immediately proceeding the newline.... character, which on output signifies the end of the current line. The return value of the printf function is of type int, but it is silently discarded since it is not used. (A more careful program might test the return value to determine whether or not the printf function succeeded.) The semicolon ; terminates the statement.
The return statement terminates the execution of the main function and causes it to return the integer value 0, which is interpreted by the run-time system as an exit code indicating successful execution.
The closing curly brace indicates the end of the code for the main function.
In computer science, weak typing is a property attributed to the type systems of some programming languages. It is the opposite of strong typing, and consequently the term weak typing has as many different meanings as strong typing does .... type system
Type system
In computer science, a type system may be defined as "a tractable syntactic method for proving the absence of certain program behaviors by classifying phrases according to the kinds of values they compute.".... that shares some similarities with that of other ALGOL
Algol
Algol , known colloquially as the Demon Star, is a bright star in the constellation Perseus . It is one of the best known eclipsing binary, the first such star to be discovered, and also one of the first variable stars to be discovered.... descendants such as Pascal
Pascal (programming language)
Pascal is an influential imperative programming and Procedural programming programming language, designed in 1968/9 and published in 1970 by Niklaus Wirth as a small and efficient language intended to encourage good programming practices using structured programming and data structure.... . There are built-in types for integers of various sizes, both signed and unsigned, floating-point numbers, characters, and enumerated types (enum). C99 added a boolean datatype
Boolean datatype
In computer science, the Boolean algebra datatype, sometimes called the logical datatype, is a primitive datatype having one of two values: Truth value and false.... . There are also derived types including array
Array
In computer science, an array is a data structure consisting of a group of element s that are accessed by index . In most programming languages each element has the same data type and the array occupies a contiguous area of computer memory.... s, pointers, records
Record (computer science)
In computer science, a record type or struct is a type whose values are records, i.e. aggregates of several items of possibly different types.... (struct), and untagged unions
Union (computer science)
In computer science, a union is a data structure that stores one of several types of data at a single location. There are only two safe ways of accessing a union object.... (union).
C is often used in low-level systems programming where escapes from the type system may be necessary. The compiler attempts to ensure type correctness of most expressions, but the programmer can override the checks in various ways, either by using a type cast
Type conversion
In computer science, type conversion or typecasting refers to changing an entity of one data type into another. This is done to take advantage of certain features of type hierarchies.... to explicitly convert a value from one type to another, or by using pointers or unions to reinterpret the underlying bits of a value in some other way.
Pointers
C supports the use of pointers, a very simple type of reference
Reference (computer science)
In computer science, a reference is an object containing information about how to locate and access the particular data item, as opposed to containing the data itself.... that records, in effect, the address or location of an object or function in memory. Pointers can be dereferenced to access data stored at the address pointed to, or to invoke a pointed-to function. Pointers can be manipulated using assignment and also pointer arithmetic. The run-time representation of a pointer value is typically a raw memory address (perhaps augmented by an offset-within-word field), but since a pointer's type includes the type of the thing pointed to, expressions including pointers can be type-checked at compile time. Pointer arithmetic is automatically scaled by the size of the pointed-to data type. (See Array-pointer interchangeability below.) Pointers are used for many different purposes in C. Text strings
String (computer science)
In computer programming and some branches of mathematics, a string is an ordered sequence of symbols. These symbols are chosen from a predetermined set or alphabet.... are commonly manipulated using pointers into arrays of characters. Dynamic memory allocation
Dynamic memory allocation
In computer science, dynamic memory allocation is the allocation of computer storage storage for use in a computer program during the runtime of that program.... , which is described below, is performed using pointers. Many data types, such as tree
Tree (data structure)
In computer science, a tree is a widely-used data structure that emulates a hierarchical tree structure with a set of linked Vertex_. It is an acyclic connected graph where each node has a set of zero or more children nodes, and at most one parent node.... s, are commonly implemented as dynamically allocated struct objects linked together using pointers. Pointers to functions are useful for callbacks
Callback (computer science)
In computer programming, a callback is executable code that is passed as an argument to other code. It allows a lower-level abstraction layer to call a subroutine defined in a higher-level layer.... from event handlers.
A null pointer is a pointer value that points to no valid location (it is often represented by address zero). Dereferencing a null pointer is therefore meaningless, typically resulting in a run-time error. Null pointers are useful for indicating special cases such as no next pointer in the final node of a linked list
Linked list
In computer science, a linked list is one of the fundamental data structures, and can be used to implement other data structures. It consists of a sequence of node s, each containing arbitrary data Field s and one or two reference s pointing to the next and/or previous nodes.... , or as an error indication from functions returning pointers.
Void pointers (void *) point to objects of unknown type, and can therefore be used as "generic" data pointers. Since the size and type of the pointed-to object is not known, void pointers cannot be dereferenced, nor is pointer arithmetic on them allowed, although they can easily be (and in many contexts implicitly are) converted to and from any other object pointer type.
Careless use of pointers is potentially dangerous. Because they are typically unchecked, a pointer variable can be made to point to any arbitrary location, which can cause undesirable effects. Although properly-used pointers point to safe places, they can be made to point to unsafe places by using invalid pointer arithmetic
Data pointer
In computer science, a pointer is a programming language data type whose value refers directly to another value stored elsewhere in the computer memory using its Memory address.... ; the objects they point to may be deallocated and reused (dangling pointer
Dangling pointer
Dangling pointers and wild pointers in computer programming are data pointer that do not point to a valid object of the appropriate type. Dangling pointers arise when an object is deleted or deallocated, without modifying the value of the pointer, so that the pointer still points to the memory location of the deallocated memory.... s); they may be used without having been initialized (wild pointers); or they may be directly assigned an unsafe value using a cast, union, or through another corrupt pointer. In general, C is permissive in allowing manipulation of and conversion between pointer types, although compilers typically provide options for various levels of checking. Some other programming languages address these problems by using more restrictive reference
Reference (computer science)
In computer science, a reference is an object containing information about how to locate and access the particular data item, as opposed to containing the data itself.... types.
In computer science, an array is a data structure consisting of a group of element s that are accessed by index . In most programming languages each element has the same data type and the array occupies a contiguous area of computer memory.... types in C are traditionally, of a fixed, static size specified at compile time. (The more recent C99 standard also allows a form of variable-length arrays.) However, it is also possible to allocate a block of memory (of arbitrary size) at run-time, using the standard library's malloc function, and treat it as an array. C's unification of arrays and pointers (see below) means that true arrays and these dynamically-allocated, simulated arrays are virtually interchangeable. Since arrays are always accessed (in effect) via pointers, array accesses are typically not checked against the underlying array size, although the compiler may provide bounds checking as an option. Array bounds violations are therefore possible and rather common in carelessly written code, and can lead to various repercussions, including illegal memory accesses, corruption of data, buffer overruns, and run-time exceptions.
C does not have a special provision for declaring multidimensional arrays, but rather relies on recursion within the type system to declare arrays of arrays, which effectively accomplishes the same thing. The index values of the resulting "multidimensional array" can be thought of as increasing in row-major order
Row-major order
In computing, row-major order and column-major order describe methods for storing multidimensional arrays in linear memory. Following standard matrix notation, rows are identified by the first index of a two-dimensional array and columns by the second index.... .
Although C supports static arrays, it is not required that array indices be validated (bounds checking
Bounds checking
In computer programming, bounds checking is any method of detecting whether a variable is within some bounds before its use. It is particularly relevant to a variable used as an index into an array to ensure its value lies within the bounds of the array.... ). For example, one can try to write to the sixth element of an array with five elements, generally yielding undesirable results. This type of bug, called a buffer overflow
Buffer overflow
In computer security and computer programming, a buffer overflow, or buffer overrun, is an Anomaly in software condition where a process attempts to store data beyond the boundaries of a fixed-length buffer .... or buffer overrun, is notorious for causing a number of security problems. On the other hand, since bounds checking elimination technology was largely nonexistent when C was defined, bounds checking came with a severe performance penalty, particularly in numerical computation. A few years earlier, some Fortran
Fortran
Fortran is a general-purpose programming language, procedural programming language, imperative programming language programming language that is especially suited to numerical analysis and scientific computing.... compilers had a switch to toggle bounds checking on or off; however, this would have been much less useful for C, where array arguments are passed as simple pointers.
Multidimensional arrays are commonly used in numerical algorithms (mainly from applied linear algebra
Linear algebra
Linear algebra is the branch of mathematics concerned with the study of Euclidean vectors, vector spaces , linear maps , and system of linear equations.... ) to store matrices. The structure of the C array is well suited to this particular task. However, since arrays are passed merely as pointers, the bounds of the array must be known fixed values or else explicitly passed to any subroutine that requires them, and dynamically sized arrays of arrays cannot be accessed using double indexing. (A workaround for this is to allocate the array with an additional "row vector" of pointers to the columns.)
C99 introduced "variable-length arrays" which address some, but not all, of the issues with ordinary C arrays.
Array-pointer interchangeability
A distinctive (but potentially confusing) feature of C is its treatment of arrays and pointers. The array-subscript notation x[i] can also be used when x is a pointer; the interpretation (using pointer arithmetic) is to access the (i+1)th of several adjacent data objects pointed to by x, counting the object that x points to (which is x[0]) as the first element of the array.
Formally, x[i] is equivalent to *(x + i). Since the type of the pointer involved is known to the compiler at compile time, the address that x + i points to is not the address pointed to by x incremented by i bytes, but rather incremented by i multiplied by the size of an element that x points to. The size of these elements can be determined with the operator sizeof
Sizeof
In the programming languages C programming language and C++, the unary operator 'sizeof' is used to calculate the sizes of Data_type. sizeof can be applied to all datatypes, be they primitive types such as the Integer and IEEE floating-point standard types defined in the language, Data pointer, or the compound datatypes defined... by applying it to any dereferenced element of x, as in n = sizeof *x or n = sizeof x[0].
Furthermore, in most expression contexts (a notable exception is sizeof array), the name of an array is automatically converted to a pointer to the array's first element; this implies that an array is never copied as a whole when named as an argument to a function, but rather only the address of its first element is passed. Therefore, although C's function calls use pass-by-value semantics, arrays are in effect passed by reference
Reference (computer science)
In computer science, a reference is an object containing information about how to locate and access the particular data item, as opposed to containing the data itself.... .
The number of elements in a declared array a can be determined as sizeof a / sizeof a[0].
An interesting demonstration of the interchangeability of pointers and arrays is shown below. The four assignments are equivalent and each is valid C code. Note how the last line contains the strange code i[x] = 1;, which has the index variable i apparently interchanged with the array variable x. This last line might be found in obfuscated C
International Obfuscated C Code Contest
The International Obfuscated C Code Contest is a programming contest for the most creatively obfuscated code C code, held annually since 1984 with the exception of 1997, 1999, 2002, 2003, and 2006.... code.
/* x designates an array */
x[i] = 1;
(x + i) = 1;
(i + x) = 1;
i[x] = 1; /* strange, but correct: i[x] is equivalent to *(i + x) */
However, there is a distinction to be made between arrays and pointer variables. Even though the name of an array is in most expression contexts converted to a pointer (to its first element), this pointer does not itself occupy any storage. Consequently, you cannot change what an array "points to", and it is impossible to assign to an array. (Arrays may however be copied using the memcpy function, for example.)
Memory management
One of the most important functions of a programming language is to provide facilities for managing memory
Computer memory
Computer memory is usually meant to refer to the semiconductor technology that is used to store information in Electronics devices. Current primary computer memory makes use of integrated circuits consisting of silicon-based transistors.... and the objects that are stored in memory. C provides three distinct ways to allocate memory for objects:
Static memory allocation refers to the process of allocating memory at Compile time before the associated program is executed, unlike dynamic memory allocation or automatic memory allocation where memory is allocated as required at Runtime.... : space for the object is provided in the binary at compile-time; these objects have an extent
Variable
A variable is a symbol that stands for a value that may vary; the term usually occurs in opposition to constant, which is a symbol for a non-varying value, i.e.... (or lifetime) as long as the binary which contains them is loaded into memory
In computer programming, an automatic variable is a scope variable which is allocated and de-allocated automatically when program flow enters and leaves the variable's scope .... : temporary objects can be stored on the stack
Call stack
In computer science, a call stack is a dynamic Stack data structure that stores information about the active subroutines of a computer program.... , and this space is automatically freed and reusable after the block in which they are declared is exited
In computer science, dynamic memory allocation is the allocation of computer storage storage for use in a computer program during the runtime of that program.... : blocks of memory of arbitrary size can be requested at run-time using library functions such as malloc
Malloc
In computing, malloc is a subroutine provided in the C and C++'s standard library for performing dynamic memory allocation.... from a region of memory called the heap
Dynamic memory allocation
In computer science, dynamic memory allocation is the allocation of computer storage storage for use in a computer program during the runtime of that program.... ; these blocks persist until subsequently freed for reuse by calling the library function free
Malloc
In computing, malloc is a subroutine provided in the C and C++'s standard library for performing dynamic memory allocation....
These three approaches are appropriate in different situations and have various tradeoffs. For example, static memory allocation has no allocation overhead, automatic allocation may involve a small amount of overhead, and dynamic memory allocation can potentially have a great deal of overhead for both allocation and deallocation. On the other hand, stack space is typically much more limited and transient than either static memory or heap space, and dynamic memory allocation allows allocation of objects whose size is known only at run-time. Most C programs make extensive use of all three.
Where possible, automatic or static allocation is usually preferred because the storage is managed by the compiler, freeing the programmer of the potentially error-prone chore of manually allocating and releasing storage. However, many data structures can grow in size at runtime, and since static allocations (and automatic allocations in C89 and C90) must have a fixed size at compile-time, there are many situations in which dynamic allocation must be used. Prior to the C99 standard, variable-sized arrays were a common example of this (see "malloc
Malloc
In computing, malloc is a subroutine provided in the C and C++'s standard library for performing dynamic memory allocation.... " for an example of dynamically allocated arrays).
Automatically and dynamically allocated objects are only initialized if an initialized is explicitly specified; otherwise they initially have indeterminate values (typically, whatever bit pattern
Bit
A bit is a binary numeral system numerical digit, taking a value of either 0 or 1. Binary digits are a basic unit of information Computer data storage and transmission in digital computing and digital information theory.... happens to be present in the storage
Computer storage
Computer data storage, often called storage or memory, refers to computer components, devices, and recording medium that retain digital data used for computing for some interval of time.... , which might not even represent a valid value for that type). If the program attempts to access an uninitialized value, the results are undefined. Many modern compilers try to detect and warn about this problem, but both false positives and false negatives
Type I and type II errors
In statistics, the terms Type I error and type II error are used to describe possible errors made in a statistical decision process. In 1928, Jerzy Neyman and Egon Pearson , both eminent statisticians, discussed the problems associated with "deciding whether or not a particular sample may be judged as likely to have been randomly dr... occur.
Another issue is that heap memory allocation has to be manually synchronized with its actual usage in any program in order for it to be reused as much as possible. For example, if the only pointer to a heap memory allocation goes out of scope or has its value overwritten before free
Malloc
In computing, malloc is a subroutine provided in the C and C++'s standard library for performing dynamic memory allocation.... has been called, then that memory cannot be recovered for later reuse and is essentially lost to the program, a phenomenon known as a memory leak
Memory leak
In computer science, a memory leak is a particular type of unintentional memory consumption by a computer program where the program fails to release dynamic memory when no longer needed.... . Conversely, it is possible to release memory too soon and continue to access it; however, since the allocation system can re-allocate or itself use the freed memory, unpredictable behavior is likely to occur when the multiple users corrupt each other's data. Typically, the symptoms will appear in a portion of the program far removed from the actual error. Such issues are ameliorated in languages with automatic garbage collection
Garbage collection (computer science)
In computer science, garbage collection is a form of automatic memory management. The garbage collector, or just collector, attempts to reclaim garbage , or memory used by Object that will never be accessed or mutated again by the Application software.... or RAII
Resource Acquisition Is Initialization
Resource Acquisition Is Initialization, often referred to by the acronym RAII, is a popular design pattern in several Object-oriented_programming_language like C++, D and Ada .... .
Libraries
The C programming language uses libraries as its primary method of extension. In C, a library is a set of functions contained within a single "archive" file. Each library typically has a header file, which contains the prototypes of the functions contained within the library that may be used by a program, and declarations of special data types and macro symbols used with these functions. In order for a program to use a library, it must include the library's header file, and the library must be linked with the program, which in many cases requires compiler flags (e.g., -lm, shorthand for "math library").
The C standard library consists of a set of sections of the ISO C standard which describe a collection of header files and library routines used to implement common operations, such as input/output and character string handling, in the C .... , which is specified by the ISO and ANSI C
ANSI C
ANSI C is the standard published by the American National Standards Institute for the C . Software developers writing in C are encouraged to conform to the requirements in the document, as it encourages easily porting code.... standards and comes with every C implementation. ("Freestanding" [embedded] C implementations may provide only a subset of the standard library.) This library supports stream input and output, memory allocation, mathematics, character strings, and time values.
Another common set of C library functions are those used by applications specifically targeted for Unix
Unix
Unix is a computer operating system originally developed in 1969 by a group of American Telephone & Telegraph employees at Bell Labs, including Ken Thompson , Dennis Ritchie, Douglas McIlroy, and Joe Ossanna.... and Unix-like
Unix-like
A Unix-like operating system is one that behaves in a manner similar to a Unix system, while not necessarily conforming to or being certified to any version of the Single UNIX Specification.... systems, especially functions which provide an interface to the kernel. These functions are detailed in various standards such as POSIX
POSIX
POSIX or "Portable Operating System Interface" is the collective name of a family of related standardizations specified by the Institute of Electrical and Electronics Engineers to define the application programming interface , along with shell and utilities interfaces for software compatible with variants of the Unix operating system, altho... and the Single UNIX Specification
Single UNIX Specification
The Single UNIX Specification is the collective name of a family of standards for computer operating systems to qualify for the name "Unix". The SUS is developed and maintained by the Austin Group, based on earlier work by the IEEE and The Open Group.... .
Since many programs have been written in C, there are a wide variety of other libraries available. Libraries are often written in C because C compilers generate efficient object code; programmers then create interfaces to the library so that the routines can be used from higher-level languages like Java
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java .... , Perl
Perl
In computer programming, Perl is a high-level programming language, List of programming languages by category, Interpreter , dynamic programming language.... , and Python
Python (programming language)
Python is a general-purpose high-level programming language. Its design philosophy emphasizes code readability. Python's core syntax and semantics are Minimalism , while the standard library is large and comprehensive.... .
Deficiencies
Although the C language is extremely concise, C is subtle, and expert competency in C is not common—taking more than ten years to achieve. C programs are also notorious for security vulnerabilities due to the unconstrained direct access to memory of many of the standard C library function calls.
In spite of its popularity and elegance, real-world C programs commonly suffer from instability and memory leaks, to the extent that any appreciable C programming project will have to adopt specialized practices and tools to mitigate spiraling damage. Indeed, an entire industry has been born merely out of the need to stabilize large source-code bases.
Microsoft Corporation is a multinational corporation computer technology corporation that develops, manufactures, licenses, and supports a wide range of computer software products for computing devices.... adopted C as the core language of its operating systems. Although all standard C library calls are supported by Windows
Microsoft Windows
Microsoft Windows is a series of software operating systems and graphical user interfaces produced by Microsoft. Microsoft first introduced an operating environment named Windows in November 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces .... , there is only ad-hoc support for Unix functionality side-by-side with many Windows-specific API
Application programming interface
An application programming interface is a set of subroutine, data structures, class and/or Protocol provided by library and/or operating system Service s in order to support the building of applications.... calls.
In computing, endianness is the byte ordering used to represent some kind of data. Typical cases are the order in which integer values are stored as bytes in computer memory and the transmission order over a network or other medium.... of its types—for example, each compiler is free to choose the size of an int type as anything over 16 bits according to what is efficient on the current platform. Many programmers work based on size and endianness assumptions, leading to code that is not portable
Software portability
Portability is one of the key concepts of High-level programming language. Portability is the software codebase feature to be able to reuse the existing code instead of creating new code when moving software from an environment to another.... .
The C standard defines only a very limited gamut of functionality, excluding anything related to network communications, user interaction, or process/thread creation. Its parent document, the POSIX standard, includes such a wide array of functionality that no operating system appears to support it exactly, and only Unix systems have even attempted to support substantial parts of it.
Therefore the kinds of programs that can be portably written are extremely restricted, unless specialized programming practices are adopted.
Language tools
Tools have been created to help C programmers avoid some of the problems inherent in the language, such as statements with undefined behavior or statements that are not a good practice because they are more likely to result in unintended behavior or run-time errors.
Automated source code checking and auditing are beneficial in any language, and for C many such tools exist, such as Lint
Lint programming tool
In computer programming, lint was the name originally given to a particular program that flagged suspicious and non-portable constructs in C source code.... . A common practice is to use Lint to detect questionable code when a program is first written. Once a program passes Lint, it is then compiled using the C compiler. Also, many compilers can optionally warn about syntactically valid constructs that are likely to actually be errors. MISRA C
MISRA C
MISRA C is a software development standard for the C programming language developed by MISRA . Its aims are to facilitate code safety, portability and reliability in the context of embedded systems, specifically those systems programmed in ISO C.... is a proprietary set of guidelines to avoid such questionable code, developed for embedded systems.
There are also compilers, libraries and operating system level mechanisms for performing array bounds checking, buffer overflow
Buffer overflow
In computer security and computer programming, a buffer overflow, or buffer overrun, is an Anomaly in software condition where a process attempts to store data beyond the boundaries of a fixed-length buffer .... detection, serialization
Serialization
In computer science, in the context of data storage and transmission, serialization is the process of converting an object into a sequence of bits so that it can be stored on a storage medium or transmitted across a computer network connection link.... and automatic garbage collection
Garbage collection (computer science)
In computer science, garbage collection is a form of automatic memory management. The garbage collector, or just collector, attempts to reclaim garbage , or memory used by Object that will never be accessed or mutated again by the Application software.... , that are not a standard part of C.
Valgrind is a programming tool for memory debugger, memory leak detection, and performance analysis. The name Valgrind comes from the name of the main entrance to Valhalla in Norse mythology.... , and linking with libraries containing special versions of the memory allocation functions
Malloc
In computing, malloc is a subroutine provided in the C and C++'s standard library for performing dynamic memory allocation.... can help uncover runtime memory errors.
Related languages
C has directly or indirectly influenced many later languages such as Java
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java .... , C#, Perl
Perl
In computer programming, Perl is a high-level programming language, List of programming languages by category, Interpreter , dynamic programming language.... , PHP
PHP
PHP is a scripting language originally designed for producing dynamic web pages. It has evolved to include a command line interface capability and can be used in Standalone software Graphical user interface.... , JavaScript
JavaScript
JavaScript is a scripting language widely used for client-side web development. It was the originating Programming language dialect of the ECMAScript standard.... , LPC, and Unix's C Shell
C shell
The C shell is a Unix shell developed by Bill Joy for the Berkeley Software Distribution Unix system. It was originally derived from the 6th Edition Unix /bin/sh , the predecessor of the Bourne shell.... . The most pervasive influence has been syntactical: all of the languages mentioned combine the statement and (more or less recognizably) expression syntax of C with type systems, data models and/or large-scale program structures that differ from those of C, sometimes radically.
When object-oriented languages became popular, C++
C++
C++ is a general-purpose programming language. It is regarded as a middle-level language, as it comprises a combination of both high-level programming language and low-level programming language language features.... and Objective-C
Objective-C
Objective-C is a Reflection , Object-oriented programming programming language which adds Smalltalk-style message passing to C .Today it is used primarily on Mac OS X, iPhone OS, and GNUstep, three environments based on the OpenStep standard, and is the primary language used for the NEXTSTEP, OpenStep#OPENSTEP, and Cocoa application framew... were two different extensions of C that provided object-oriented capabilities. Both languages were originally implemented as source-to-source compiler
Source-to-source compiler
A "source-to-source compiler" is a type of compiler that takes a high level language as its input and outputs a high level language. For example, an automatic Parallel compiler will frequently take in a high level language program as an input and then transform the code and annotate it with parallel code annotations or language constructs .... s -- source code was translated into C, and then compiled with a C compiler.
Bjarne Stroustrup is a computer scientist at the College of Engineering Chair Professor of Computer Science at Texas A&M University. He is most notable for developing the C++ programming language.... devised the C++ programming language as one approach to providing object-oriented functionality with C-like syntax. C++ adds greater typing strength, scoping and other tools useful in object-oriented programming and permits generic programming
Generic programming
Generic programming is a style of computer programming in which algorithms are written in terms of to-be-specified-later types that are then instantiated when needed for specific types provided as parameters and was pioneered by Ada which appeared in 1983.... via templates. Nearly a superset of C, C++ now supports most of C, with a few exceptions (see Compatibility of C and C++
Compatibility of C and C++
The C programming language and C++ programming languages are closely related. C++ grew out of C and is mostly a superset of the latter. Due to this, C code is often developed with C++ Integrated development environment, integrated with C++ code, and compiled in C++ compilers.... for an exhaustive list of differences).
Unlike C++, which maintains nearly complete backwards compatibility with C, the D language
D (programming language)
The D programming language, also known simply as D, is an Object-oriented programming, Imperative programming, Multi-paradigm programming language system programming language by Walter Bright of Digital Mars.... makes a clean break with C while maintaining the same general syntax. It abandons a number of features of C which Walter Bright
Walter Bright
Walter Bright is a computer programmer known for being the designer of the D . He was also the main developer of the first native C++ compiler, Zortech C++ .... (the designer of D) considered undesirable, including the C preprocessor
C preprocessor
The C preprocessor is the preprocessor for the C . In many C implementations, it is a separate computer program invoked by the compiler as the first part of translation.... and trigraph
C trigraph
In computer programming, digraphs and trigraphs are sequences of two and three character s respectively which are interpreted as one character by the programming language.... s. Some, but not all, of D's extensions to C overlap with those of C++.
Objective-C is a Reflection , Object-oriented programming programming language which adds Smalltalk-style message passing to C .Today it is used primarily on Mac OS X, iPhone OS, and GNUstep, three environments based on the OpenStep standard, and is the primary language used for the NEXTSTEP, OpenStep#OPENSTEP, and Cocoa application framew... was originally a very "thin" layer on top of, and remains a strict superset of, C that permits object-oriented programming using a hybrid dynamic/static typing paradigm. Objective-C derives its syntax from both C and Smalltalk
Smalltalk
Smalltalk is an Object-oriented programming, Type system, reflection computer programming programming language. Smalltalk was created as the language to underpin the "new world" of computing exemplified by "human?computer symbiosis." It was designed and created in part for educational use, more so for constructionist learning, at PARC by Al... : syntax that involves preprocessing, expressions, function declarations and function calls is inherited from C, while the syntax for object-oriented features was originally taken from Smalltalk.
Limbo is a language developed by the same team at Bell Labs that was responsible for C and Unix, and while retaining some of the syntax and the general style, introduced garbage collection, CSP
Communicating sequential processes
In computer science, Communicating Sequential Processes is a specification language for describing patterns of interaction in concurrent systems.... based concurrency and other major innovations.
Programming languages are used for controlling the behavior of a machine . Like natural languages, programming languages conform to rules for syntax and semantics....
The International Obfuscated C Code Contest is a programming contest for the most creatively obfuscated code C code, held annually since 1984 with the exception of 1997, 1999, 2002, 2003, and 2006....
The computer programming languages C and Pascal are often compared to each other, sometimes heatedly, probably because the languages have similar times of origin, influences, and purposes, and so represent two philosophical approaches to a similar need....
Footnotes
External links
,
(official Web site)
by Dennis M. Ritchie
by M.Banahan-D.Brady-M.Doran (Addison-Wesley, 2nd ed.) — book for beginning and intermediate students, now out of print and free to download.