Hello World in C

From Free Knowledge Base- The DUCK Project: information for everyone
Revision as of 18:20, 20 June 2007 by Admin (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Hello World is the typical minimum-function program that prints a message 
and exits successfully. This is an example written in C.

#include <stdio.h>

int main(int argc, char *argv[])
{
  printf("Hello, world!");
  exit(0);
}

The first line imports function declarations including printf(). The next 
line starts the definition of the main() function, which is called when 
your program is run. The curly braces enclose the contents of the main() 
function. The printf() call does the actual printing. The exit(0); line 
exits main() successfully. It could have just as easily have said 
return 0;, but the intent of exit() is more clear.