Spartan025's - C++ Variable

Post here about scripting and programming for HaloPC (audio, network, ai, etc.)
Post Reply
Spartan025





Posts: 13
Joined: Fri Oct 13, 2006 3:45 pm
Location: Learning C++

Spartan025's - C++ Variable

Post by Spartan025 »

C++ Variables.

In C++ there are storages in the computer that holds data. There are many specific types of data.

Code: Select all

int (variable name) // Integer, negative 2 billion to positive 2 billion
double (variable name) // Double-precison floating pt. 15 deciaml places
float (variable name) // single float pt.
bool (variable name) // Bool data: true or false
char (variable name)[bytes] // string or text
*p (variable name)//pointer, takes numerical adresses

// All these are variable types or a special storage that has specific 
// type of data
int variable type
Example: int halo_kills
The program makes a storage in the cpu with integer type named
halo_kills. This data can now be manipulated or displayed in any way you wish. This is used for counting and should not be used for decimals.

*if you use decimals in int types, the decimal is truncated or taken off
*example 3.5, .5 is cutt off, and this is a big deal, if you made a program
*that had to calculate the bytes of a halo map and you lost some numbers
*the calculation would be all wrong producing a bad halo map
*program

only use int for numbers that are not decimals. Int varibales serve as good loop variables.

4 bytes


Double Type
Example double halo_ratio_kills // Creates space in cpu with type double named halo_ratio_kills.

The reason you would use double because ratios often come out in decimals and double is the best for deciamls, they do not have the truncating problem like the int and can store bigger values. Double is not advised for loop variables


float type
Same thing as double e.g float halo_ratio_kills
but float does not have the range and accuracy of double, but double takes up more space unlike float.

Float space:4 bytes
Double space:8 bytes


Bool Type
Example bool do_u_like_halo // Creates space in the cpu that takes true and false statements name do_u_like_halo.

boolean flags: true;
false;

alternately you could use 1 for true and 0 for false

4 bytes.


Char
example char game_name[10] // Creates space in the cpu that has a text value called game_name. the "[10]" is how many bytes the string or char has. This can vary depending how long the word or text is.


Pointer
examle (data type) * ip adress// Creates a variable that gets numerical adresses or the orinial places of variables not copies. Variables are the only way to pass data from one function to another. The numerical variable to be read must match the data or base types


Variable Conventions
-make sure variables are descriptive.
-make them lower case
-seperate each word with an underscore(_)
-do not use C++ keywords
-you can only use the alphabet, 0-9 and _

Code: Select all

#include <iostream>
using namespace std;

int main() {
        cout << "Initiate Control Room Console" << endl;
        cout << "Initiate functions......" << endl
        system("PAUSE");
        return 0;
}
User avatar
kornman00




ONI New Age

Posts: 146
Joined: Fri Dec 12, 2003 6:30 pm
Contact:

Post by kornman00 »

This is EXACTLY why halomods is the way it is today. Because people pull shit out of their ass without knowing what the hell they're talking about, and\or doing
User avatar
xbox7887




Socialist Coagulator Decryptor Advisor
Eureka Commentator Wave Scorched Earth

Posts: 2160
Joined: Mon Dec 27, 2004 6:19 pm
Location: New Lenox, Illinois
Contact:

Post by xbox7887 »

Variables are stored in memory, not the cpu. Local variables and args get stored or pushed on the stack, and global variables get stored in a separate data section . The only way variables get stored in the cpu is when you optimize your code or use fastcalls, then they can be passed through the cpu registers :?
Post Reply