Main Gestures Programming Music Whoizzy? Links

C Programming

Part 1
Hello World

#include <stdio.h>

int main(void)
{
	printf("Hello There!!"); /* Print 'Hello There!!' to the screen */
	return 0;
}


What's going on here? All this program does is print 'Hello There..." to the monitor. I'll go line by line.

LINE 1:
#include <stdio.h>

This is a preprocessor directive. It tells the compiler to include the contents of the header file stdio.h to your program before it's compiled (preprocessing).

Stdio.h holds many functions for input and output (Stdio = Standard Input/Output). A function is just a well defined task. Without this file, there is no interaction in your programs with the user. We are taking advantage of the printf() function to display the words to the screen. You will be using this line #include <stdio.h> in all your programs if they have input and output.

LINE 2:
int main(void)

This is the first line of the main function. Every C program has a function called main. Main is where the program begins execution. All of the contents of main are between the characters { and }. That's all I will say on functions for now.

LINE 3:
printf("Hello There!!");

The printf("Your text..."); funtion. What we can pick up on functions from here is that you feed them with information between the ( and ). It takes that (information) and does with it what it is programmed to do. In this case, it sends it to the screen.

Notice the ;. The ; is found at the end of any statement. Think of a statement as a sentence and you will be fine.

Also notice this tidbit.
/* Print 'Hello There!!' to the screen */
Anything written between /* and */ is a comment and will not be a part of your executing program. You may write yourself comments anywhere in your code, as long as it is between /* and */.

LINE 4:
return 0;

This line essentially returns control to your operating system after the program has finished executing. I will speak more of the return statement when we talk about funtions.


NEXT LESSON

MAIN MENU

Found a broken link?
Mail Me