Hello World (C)

From LiteratePrograms

Jump to: navigation, search
Other implementations: Ada | ALGOL 68 | Alice ML | Amiga E | Applescript | AspectJ | Assembly Intel x86 Linux | Assembly Intel x86 NetBSD | AWK | bash | BASIC | Batch files | C | C, Cairo | C, Xlib | Candle | Clojure | C++ | C# | Delphi | Dylan | E | Eiffel | Erlang | Forth | FORTRAN | Fortress | Go | Groovy | Haskell | Hume | IBM PC bootstrap | Inform 7 | Java | Java, Swing | JavaScript | LaTeX | Lisp | Logo | Lua | Maple | MATLAB | Mercury | OCaml/F Sharp | occam | Oz | Pascal | Perl | PHP | Pic | PIR | PLI | PostScript | Prolog | Python | Rexx | Ruby | Scala | Scheme | Seed7 | sh | Smalltalk | SQL | Standard ML | SVG | Tcl | Tcl Tk | Visual Basic | Visual Basic .NET | XSL

This short C program prints a message to the console.

<<hello_world.c>>=
#include <stdio.h>
int main()
{
	printf("Hello World!\n");
	return 0;
}

The header file stdio.h provides the declaration for printf(). The header file is technically optional, but helps to check our printf() for type errors at compile time. C programs always enter at the beginning of a function called "main", and the result of this function is provided to the operating system. We return zero as the conventional representation of success. We could use puts() instead of printf() in this simple example.

Download code
Views
Personal tools