Simple C Hello World:
Code:
#include <stdio.h>
#include <conio.h>
/* This is a comment */
int main(void)
{
printf("Hello World!");
getch();
return 0;
}
The first 2 lines tell the compiler to include header files so functions can be carried out. stdio.h is needed for printf. conio.h is needed for getch.
The next line is a comment - anything in between /* */ is ignored by the compiler and can be used to make code easier to maintain, or just give information.
int main(void) is the first function that is started whenever the program is run. The thing after it says everything between { } is part of the main function.
printf("Hello World!"); prints Hello World! to the console window. Note the semicolon after the statement.
getch(); pauses the program until the user presses enter.
return 0; gives the main function a value of 0 after it's run. You need this line because main is declared as an integer. Some of this is probably confusing, but it'll make sense soon, I promise.