by David Hamrick |
||
| Home Links Starting Out Variables Projects
|
Hello World Tutorial
Now we are ready to start writing our first program. The first thing that we are going to want to do is include the header file stdio to our program. That lets us use all the functions that are included there. In this case we are going to want to use the function printf(). To include the header file we use this command. #include <stdio.h> Next thing we are going to want to do is get the start point for our program. That is done in a function called main(). This is where we start to execute the code written. We start the function like this. int main() We our now inside of the main function where we are going to want to write something to the standard output stream, which in plain English is just the text that shows up in your command prompt window. printf("Hello World"); We did a lot of things just there so we'll go through them step by step. First we called the function printf by typing printf. then we started to pass things to it by using a (. Whenever you call a function you will use ( ) to say what you are passing to it. In this case we are passing the text "Hello World". Whenever you want to use text you have to put " " around it to tell the compiler that it is text. Lastly to end a command we use a semicolon. Now we have 2 more things to do. We need to return a value to the computer to tell that the program ran successfully. So we are going to return a 0. And then we will use 1 more bracket to end the function main. return 0; And thats it. Wasn't to hard was it? To try it out copy and paste the following into your text editor. #include <stdio.h> int main()
|