Spartan025's - C++ Variable
Posted: Sun Mar 18, 2007 12:19 pm
C++ Variables.
In C++ there are storages in the computer that holds data. There are many specific types 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 _
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
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 _