Gw Temp

Menu

Tutorial - 'C++ Introductory' by lithium

An item about Programming Languages posted on

Blurb

Take your first step into c++ programming with Lithium.

Body

C++ Tutorial Part 1: Spacemonkey chatter.


There are alot of important things you need to learn when gahtering your wealth of c++ knowledge. C++ is a powerful scripting language used for all sort of stuff. Not just computer programs in particular but all types of hardware for your computer, maybe even your microwave is programmed in C++. What you learn here in part one is the basics of ANSI/ISO Standard C++...C++ ANSI/ISO Tutorial Part 1


::/ Hello World!


The most basic script on the face of the earth. The hello.cpp program. Everyone should learn this for it is the most basic example of this basic tutorial.

First of all, the iostream. EVERY, I will repeat, EVERY program starts of with the line

#include

IOSTREAM.h holds the input/output information needed to run the program, so remember that.

ex 1.1
---------------------
#include

int main()
{
cout << "Hail to the Squirrel!\n";
return 0;
}


------------------

Easy right. But if you a beginner and you look at that, you will all have a common response: huh? Let me explain


#include is obviously our input/output code, as explained above.
int main() is the "Go" button for the program, every C++ script has a main() function.
main() MUST state the value it will give back, but being a little warthog, it only gives you a int, I'll explain a little more later.
If there is one thing you have to remember, its that all functions start off with a brace ({) and then end with one (}), if you look on line 4 and line 7 you can see where the function took place. Be careful, everything inside the braces if part of the function, and adding unnessicary additions could confuse the complier and you'll get a variety of errors.
"cout" is your text display function, although I have no idea what "cout" has in relation to inputting text to the screen, it serves just as well. << is a redirection symbol just tells what the upcoming part of the line is part of that particular function. The quotation marks obviously mean that there is some text coming up (ex. Hail to the Squirrel!). \n tells the function "cout" to add a line after the words "Hail to the Squirrel!". Next line, we call up return 0. Basically all this does is return control to the windows operating system. And line 7 ends the code with our beloved }.

**** Notation of a Nation ****
Zero means nothing is isn't a value widely used. In UNIX and DOS it signals the success or failure to complete the script.
******************************

FUNCTIONS
Now I'll explain a little more about the main(). Whilest it is a function, albiet a strange one, because no matter what its always called when you start up your program. No other functions can do this. A program is executed line by line in the order it appears until a function is called and tell it to do otherwise, then the program takes the highway to finish the function called, then when its done, its rerturns to the next line of code where it will cotinue to go until yet another function derails it. Function return a value or the return a VOID, meaning that they have no value to use. main() ALWAYS returns an int. They are in love.