C Programming — Hello World

C Programming — Hello World

A basic C example that prints “Hello World” and explains header inclusion, the main function, printf, getch and the return value.

Prints the text “Hello World” on the screen.

#include <stdio.h>
#include <conio.h>
int main()
{
printf("Hello World");
getch();
return 0;
}
  • The #include directive indicates that the specified header file will be included. In this example, stdio.h is the header for the standard input/output library.
  • The main function is the first function executed when the program starts. The preceding int indicates that the function returns an integer.
  • The printf() function means “print formatted” and prints formatted output to the screen.
  • The getch() function is used here to prevent the window from closing. Its primary purpose is to read a character from the keyboard; conio.h must be included to use it in this example.
  • The final return 0 statement indicates that main() returns zero.

References

  • **[1]** Brian W. Kernighan; Dennis M. Ritchie. (1988). The C Programming Language, Second Edition. Prentice Hall.
  • **[2]** International Organization for Standardization. (2011). ISO/IEC 9899:2011 - Programming Languages - C. ISO.
QR code for this page