C (programming language): Difference between revisions
imported>Alex Bravo mNo edit summary |
imported>Markus Baumeister (many changes and of course the obligatory K&R reference) |
||
Line 1: | Line 1: | ||
C is a general-purpose, procedural, imperative [[computer]] [[programming language]] developed in 1972 by [[Dennis M. Ritchie]] and [[Brian W. Kernighan]] at the Bell Telephone Laboratories for use with the [[Unix]] operating system. It has since spread to every other platform, and is now one of the most widely used programming languages. It has been adapted by ISO and | C is a general-purpose, procedural, imperative [[computer]] [[programming language]] developed in 1972 by [[Dennis M. Ritchie]] and [[Brian W. Kernighan]] at the Bell Telephone Laboratories for use with the [[Unix]] operating system<ref name="K&R">Kernighan, B. and Ritchie, D.: The C Programming Language. Prentice Hall, 1978. | ||
*The original language definition before standardization.</ref>. It has since spread to basically every other platform, and is now one of the most widely used programming languages. It has been adapted by ISO and ANSI, and is considered a standard programming language. C has also greatly influenced many other popular languages, especially [[C++]], which was originally designed by [[Bjarne Stroustroup]] as an enhancement to C. Due to its basic dual nature, being low-level as well as highly structured, it is the most commonly used programming language for writing system software, though it is also widely used for writing applications. | |||
==Syntax== | ==Syntax== | ||
Line 7: | Line 8: | ||
#include <stdio.h> | #include <stdio.h> | ||
int main() { | int main(void) { | ||
printf("Hello, world!\n"); | printf("Hello, world!\n"); | ||
return 0; | return 0; | ||
} | } | ||
====Analysis==== | ====Analysis of the example==== | ||
The above [[Hello World]] program is probably the most widely recreated piece of software ever as it used by many programming languages books and articles as a cursory introduction into the language's [[syntax]]. It was introduced in <ref name="K&R"/>. | |||
<code>#include <stdio.h></code> tells the [[ | <code>#include <stdio.h></code> tells the [[precompiler]] to include the contents of the header file stdio.h, which declares '''st'''andar'''d''' '''i'''nput and '''o'''utput functions, into the program before compiling. | ||
<code>int main {</code> tells the compiler that there is a function named <code>main</code>. The opening curly brace denotes the beginning of the function. | <code>int main(void) {</code> tells the compiler that there is a [[function]] named <code>main</code> which expects no [[parameter]]s and will return a integer number to the [[caller]]. Due to a standard convention of the language, "main" is the first function called after the [[execution environment]] of the program has been set up. The opening curly brace following <code>int main(void)</code> denotes the beginning of the function. | ||
<code>printf("Hello, world!\n");</code> will make the program output <code>Hello, world!</code> and a new line (<code>\n</code>) on the screen. The semicolon is | <code>printf("Hello, world!\n");</code> will make the program output <code>Hello, world!</code> and a new line (<code>\n</code>) on the screen. "printf" is itself a function similar to "main" but predefined in a library (libc) and [[linker|linked]] into the program at compile time or runtime. The trailing semicolon is the end of statement marker in C. | ||
<code>return 0;</code> | <code>return 0;</code> defines the value to be returned from <code>main</code> and leaves the function back to its caller, some standard C startup code. After some additional cleanup that code will pass the 0 on to the [[operating system]] to which it means 'success'. | ||
<code>}</code> signals the end of the function. | <code>}</code> signals the end of the function definition to the compiler. | ||
===Citations=== | |||
<div class="references-small"> | |||
<references /> | |||
</div> | |||
==External links== | ==External links== |
Revision as of 17:27, 25 February 2007
C is a general-purpose, procedural, imperative computer programming language developed in 1972 by Dennis M. Ritchie and Brian W. Kernighan at the Bell Telephone Laboratories for use with the Unix operating system[1]. It has since spread to basically every other platform, and is now one of the most widely used programming languages. It has been adapted by ISO and ANSI, and is considered a standard programming language. C has also greatly influenced many other popular languages, especially C++, which was originally designed by Bjarne Stroustroup as an enhancement to C. Due to its basic dual nature, being low-level as well as highly structured, it is the most commonly used programming language for writing system software, though it is also widely used for writing applications.
Syntax
Hello World
#include <stdio.h> int main(void) { printf("Hello, world!\n"); return 0; }
Analysis of the example
The above Hello World program is probably the most widely recreated piece of software ever as it used by many programming languages books and articles as a cursory introduction into the language's syntax. It was introduced in [1].
#include <stdio.h>
tells the precompiler to include the contents of the header file stdio.h, which declares standard input and output functions, into the program before compiling.
int main(void) {
tells the compiler that there is a function named main
which expects no parameters and will return a integer number to the caller. Due to a standard convention of the language, "main" is the first function called after the execution environment of the program has been set up. The opening curly brace following int main(void)
denotes the beginning of the function.
printf("Hello, world!\n");
will make the program output Hello, world!
and a new line (\n
) on the screen. "printf" is itself a function similar to "main" but predefined in a library (libc) and linked into the program at compile time or runtime. The trailing semicolon is the end of statement marker in C.
return 0;
defines the value to be returned from main
and leaves the function back to its caller, some standard C startup code. After some additional cleanup that code will pass the 0 on to the operating system to which it means 'success'.
}
signals the end of the function definition to the compiler.