Wednesday, May 20, 2009

Analysis of Hello World

Today, we're going to look at an analyze how yesterday's hello world program works. We're going to do this by looking at each line of code and seeing what it does.

So let's take it from the top:

Any time you see "#include" the programmer is linking (or including) in other files of source. In this case, we are linking in the code that contains std::cout and std::cin

int main(){
Any time you see "main()" you will know that that is the first line of code exectuted by the computer. "{" dictates that all code from here until it's corresponding "}" is code that belongs to "main()".

std::cout << "Hello World!";
This line outputs "Hello World!" onto a console window.

int pause = 0;
This line declares a variable named "pause" and sets it's value to 0. (More about variables tomorrow)

std::cin >> pause;
This line asks the user to input a value for pause; Halting the program until the user enters a number and presses ENTER.

return 0;
Returns an integer value so we can leave main().

Note about ";"
";" signifies the end of a single line of code.

Now that you know how the program works, goof around and edit it a bit to better understand the code if you have some free time.

No comments:

Post a Comment