Gw Temp

Menu

Tutorial - 'C++ Tutorial: Part 3' by lithium

An item about Programming Languages posted on

Blurb

Goodness gracoius great balls of fire!

Body

Standard ANSI/ISO C++ Tutorial - Part 3 'Whatcya talkin' about Willis?"

Ah, finally part three after a long wait. I hate waiting, and I am most sure you do as well. You cannot attack me, or I will have my spanish thug named "Guido" come and kill you. That is right, murder you. Then we will dispose of your body in Bart's house... umm... sorry ;)!

We (and when I say we I mean I because you are obviously not writing the tutorial), in this part, are going to focus on a little bitch entitled 'Variables'. You will learn what RAM does to store temporary text, images, and data so that you can play your favorite games (*cough*not warcraft3, warcraft 3 sucks*cough*).

VARIABLES! Nothing your mother would ever talk about!
++++++++++++++++++++++++++++++++++++++++++++++++++++
Programs that you create need a method of storing the data (text and images) that they use. When you declare variables, it creates various ways to work with the usual values.

From a C++ standpoint, a variable is the location that your computers RAM refers to for getting stored information called up so that the computer can randomily access it at all times (hence RAM: Random Access Memory).

Here is a short explaination of what RAM does. Say you boot up a copy of Warcraft III. All the data and images amount to 700 MB worth. Your computer can't sift through all the packets on your computer to get to the data, so it calls it into the RAM (Random Access Memory, aren't I great, juss keep repeating things for you, so that you remember. I am soo good). The reason why, the more RAM you have, the faster your computer operates, is that if you have only 128 MB of RAM, the program that you boot up (we are using WC3 as an example) cannot call all of the data into the RAM, so it prioritizes. When a computer ends up prioritizing, gameplay can be slowed down, loading screens can take forever, because while you computer is trying to call data, it has to travel through all other packets to get to it. That is also why you should run defrag before you install any big game or program because it puts those data packets that get written when you install the game, at hte top of the pile, therefore easier for the computer to get to, therefore the faster it goes.

Seems complex, but it is really not. Variables not only have addresses, but you can label names on them. For example, if you label a variable named myVariable, then give it an address, the computer would then refer to the variable named "myVariable" instead of having you type a3414324:35546345io. See my point? Good, I hoped you would.

When you define a variable using C++, you MUST tell the compiler not only (I recommened Microsoft Visual C++ .Net Professional Edition. IT costs around 300 dollars but comes with a 5 year subscription to product updates and when you register the product online , Microsoft will send you a 600 page book on C++. So, I think it is worth the money) what the variables name is, but also the type of value it controls: characters, intergers, binaries, and so forth. You can call of this stuff the variables type. Basically, the variables type tells the computer how much memory to set aside for the variable.

You might want to learn that each packet in your computers memory is 1 byte length. If the variable that you create needs 2 bytes, you need to tell the compiler that it needs 2 packets. Because computers use bits and byte to represent values(That is why you usually see computer disassmbling in 1's and 0's), and because memory is measured in bytes, it is important that you understand and are comfortable with the concepts.

NOTATION OF THE GW NATION
:: Watch out! Not all computer OS's have the same size of intergers! ::

It is easy to determine what your operation systems lengths are. IT works in any compiler. Enter this code:

#include iostream.h

int main()
{
cout << "The size of an int is:\t\t"
<< sizeof(int) << " bytes.\n";
cout << "The size of a short int is:\t"
<< sizeof(short) << " bytes.\n";
cout << "The size of a long int is:\t"
<< sizeof(long) << " bytes.\n";
cout << "The size of a char is:\t\t"
<< sizeof(char) << " bytes.\n";
cout << "The size of a bool is:\t\t"
<< sizeof(bool) << " bytes.\n";
cout << "The size of a float is:\t\t"
<< sizeof(float) << " bytes.\n";
cout << "The size of a double is:\t"
<< sizeof(double) << " bytes.\n";

return 0;
}

That code will determine the exact sizes of those types on your computer with your particular complier.

Several other variable types are built into C++.

VARIABLE TYPES
++++++++++++++
unsigned short int is 2 bytes with values 0 to 65,535
short int is 2 bytes with values -32,768 to 32,767
unsigned long int is 4 bytes with values 0 to 4,294,967,295
long int is 4 bytes with values -2,147,483,648 to 2,147,483,647
char is 1 byte with 256 character values
bool is 1 byte and in either true or false
float is 4 bytes with values 1.2e-38 to 3.4e38
double is 8 bytes with values 2.2e-308 to 1.8e308

Now, I want you to absorb this. So I will stop here. Plus, my hands hurt. This has taken an hour already. I hope you understood this.

pz.