Gw Temp

Menu

Tutorial - 'Beginning C++ Part 2' by Maximo

An item about Programming Languages posted on

Blurb

Excellent, and lengthy tutorial concering the easy parts of C++, continuation of the first.

Body

This is a continuation of Part 1, and it goes straight from where I left off. Continuing the tutorial, you probably feel like all you did was type some random jumble of words and letters and give them to the compiler. Well, this part of the tutorial explains what everything in that compiler is. And if I make a part 3-well, I'll surprise you, I guess. Okay, here's where I start. When your compiler (Dev-C++ right now) compiles the code that you input to it in a down the line way. It starts from the top, and keeps going down the line. But there's one thing that makes everything different. Everything inside of this block of code is what's interpreted. This is called the main function. Or, just simply, main! :D That's where you typed in all that stuff, you know? "Hello, world!", cout, all that jazz. Now, I'll move on, to what's inside of main. Going DIRECTLY down from main, you see a brace ({ and }) Those aren't really inside main, but you know. Those are how the compiler tells what main is. If you don't have those, it's not main. ^_^ Now, you see cout. Don't you think it looks like it's pronounced "Cout"? That's how I used to think it was. But the best way to get out of a bad habit, is to stay out of them. :D It's really pronounced like "See-out". That stands for Console Output. You get it, right? The black window is called a console window. Cout, means that you want to write something to the compiler. After that, you see <<. That's for your cout function right before it. That tells the compiler that there's something you want displayed RIGHT after. In this case, "Hello, World!" was put in. Notice the quotes. Make sure not to forget those!!! Otherwise, it'll think of Hello and World as functions. And those functions are not real! There are no such functions, so you'll get a compiler error. And then you see the odd looking << operator again. (<< is an operator. So it's the << operator.) But wait! Maximo taught me that what comes after the << operator is typed out on the screen. Yes, I told you that. And it's true. But endl; (the function that follows) is a function. endl; ends the line. So that means that if you wrote multiple lines of code that just said "cout << endl;" over and over again, you would just have blank lines, over and over again. Then, if you finally typed in a cout line, you'd see it is very low in the console box! endl means end the line. Remember that every single little line of code ends with a semicolon. Hmm... Well, it's not accurate to say that every line ends with a semicolon. Just declarative ones. Just like sentences in the english alphabet, (ones that could end with a period or exclamation point/mark.) end those with semicolons. system("PAUSE"); is a function that you don't need to worry about, Dev-C++ adds it there for you. That's the thing that tells you "Press any key to continue..." :D return 0; is what ends the execution of the program. There, that wasn't so hard, was it? Great job, see you next time!