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
#includedirective indicates that the specified header file will be included. In this example,stdio.his the header for the standard input/output library.
- The
mainfunction is the first function executed when the program starts. The precedingintindicates 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.hmust be included to use it in this example.
- The final
return 0statement indicates thatmain()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.