Hello World in C

From LQWiki
Jump to navigation Jump to 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.