Hello World (C)

From LiteratePrograms
Jump to: navigation, search
Other implementations: Alice ML | Amiga E | AspectJ | Assembly Intel x86 Linux | Assembly Intel x86 NetBSD | AWK | bash | BASIC | Batch files | C | C, Cairo | C, Xlib | Candle | C++ | C# | Dylan | E | Forth | FORTRAN | Fortress | Go | Groovy | Haskell | IBM PC bootstrap | Inform 7 | Java | JavaScript | LaTeX | Logo | Lua | MATLAB | Mercury | OCaml/F Sharp | occam | Oz | Perl | PHP | PIR | PLI | Prolog | Python | Rexx | Ruby | Scala | Scheme | Seed7 | sh | SQL | Standard ML | Tcl | Tcl Tk | Visual Basic | 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 (of type int, for integer) 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
hijacker
hijacker
hijacker
hijacker