int main (int argc, char ** argv) {
printf("Hello World!\n");
return 0;
}
Here's a step by step explanation:
#include <stdio.h>
This statement lets the compiler know about the standard input/output functions (e.g. reading and writing to command prompt, reading and writing to files). Without it, the compiler won't recognize these functions and will not be able to use them.
int main (int argc, char ** argv)
This is the signature of the main function. The first word, int, indicates that this function returns an integer (I'll explain why later). The second word, main, gives the name of the function. Every C program must have a main function, that's where the program starts. The two things in parentheses are parameters. They're the information given to function. For main, the operating system always passes two parameters to it, argc and argv. Together they represent the command line arguments to the program when run from the command prompt. It isn't really something you need to worry about now, just remember to put them in when you write main.
{
}
The braces indicate that the code which they surround is the body of the thing immediately preceding them. So the code in the braces is the body of main.
printf("Hello World!\n"); printf is C's command prompt writing function. It takes a string (series of letters) and prints it. It can also take variables and print them, but you don't need to worry about that yet. Also, notice the \n? That simply creates a new line. Without it, when someone runs your program, this will happen: C:\blah\>hello.exe
Hello World!C:\blah\>
Doesn't look very good, does it? Remember to terminate output with a new line!
return 0;
Remember earlier when I said that main returns an integer? This is it. The operating system wants to know whether the program completed successfully or not, so we return an integer code to it. 0 is success, any other number is failure. Usually we choose one number for each potential point of error, so that if there is a problem we can look at the number and find out what the error is. But a program this simple shouldn't have any errors so no need to consider that sort of thing.
If you have any other questions feel free to ask :-)