CFORBEGINNERS.COM

C Basics

#include <stdio.h>
#include <stdlib.h>

This is what's called a pre-processor directive. What this does is tell the compiler that you are going to be including the standard input output functions in the C library, the .h tells the compiler that it is a header file. The stdandard library is another header file you will need often. This will be in every single program you write with C so do your best to remember it. Our next line is also going to be something that we will always need hmmm how did it go again oh yes!

int main()
{

The int just stands for integer why is integer even there? Well you are telling the program that when you are done with main that you will return an integer, you will see soon enough. Main is simply the name we are giving it although it does have to be main so don't go and get creative and change it. The () is also something that has to be there even if you aren't planning on putting anything in them, only in more sophisticated programs will you put something in them. Last is the curly brace { it's best to look at these as beginning and end, the { symbol being the beginning and } symbol being the end, I haven't put the ending ones yet because we haven't finished main, which brings us to our next line of code.

printf("My first program! Oh and hello world\n");

Printf means that you want to literally print something to the screen whatever is inside the quotations is what will print. The \n is just an escape sequence, whenever you put one of these it will skip to the next line, very similar to when you push the enter button while you are typing. After the parenthesis you need a semicolon, this is mandatory for a statement and all printf functions don't forget it, without it your program will not run. Also last thing, remember the standard input output pre-processor directive well by us declaring that we are able to use printf since it is output.

<
system("pause");

System pause is simple all it is doing is pausing the program giving you time to see what has been executed so far just remember to put the pause in quotes and parenthesis and end it all with semicolon.

return 0;
}

Remember when I said we put int for integer before main because we would return and integer well here it is we are returning 0, this means everything went according to plan. Now that we are finished with main we can end it with a }.

#include <stdio.h>
#include <stdlib.h>

int main()
{
printf("My first program! Oh and hello world\n");

system ("pause");
return 0;
}

If you haven't already tried coding it give it a shot, I know I know it isn't very interesting buy hey it's a start!