C (programming language): Difference between revisions

From Citizendium
Jump to navigation Jump to search
imported>Alex Bravo
imported>Alex Bravo
Line 16: Line 16:
This program is the most widely created piece of software ever.
This program is the most widely created piece of software ever.


<code>#include <stdio.h></code> tells the compiler to include the contents of the header file stdio.h, which manages '''st'''andar'''d''' '''i'''nput and '''o'''utput, into the program before compiling.
<code>#include <stdio.h></code> tells the [[compiler]] to include the contents of the header file stdio.h, which manages '''st'''andar'''d''' '''i'''nput and '''o'''utput, 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 {</code> tells the compiler that there is a function named <code>main</code>. The opening curly brace denotes the beginning of the function.
Line 22: Line 22:
<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 added to the end of every line such as a function call.
<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 added to the end of every line such as a function call.


<code>return 0;</code> returns a value from <code>main</code> to the operating system. 0 means success.
<code>return 0;</code> returns a value from <code>main</code> to the [[operating system]]. 0 means success.


<code>}</code> signals the end of the function.
<code>}</code> signals the end of the function.

Revision as of 17:19, 24 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. 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 ANSII, 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() {
   printf("Hello, world!\n");
   return 0;
}

Analysis

This program is the most widely created piece of software ever.

#include <stdio.h> tells the compiler to include the contents of the header file stdio.h, which manages standard input and output, into the program before compiling.

int main { tells the compiler that there is a function named main. The opening curly brace 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. The semicolon is added to the end of every line such as a function call.

return 0; returns a value from main to the operating system. 0 means success.

} signals the end of the function.