|
|
Data Types
When writing a program, you will often want to store a specific value for later
use. To do this, we generally use what is known as a variable (usually shortened
to var). A variable
has a name, a value and a data type. Making a new
variable is known as declaring (or instanciating) it. Some programming languages require you
to specify data type every time you declare a variable, others can detect some data
types simply by the value provided. The different data types are as follows:
Boolean (Often shortened to bool)
Booleans are the simplest of all data types. They can only contain two different
values: True or False. Despite their limited number of values, these variables are
still very useful.
Example:
var isPluggedIn = true; // Double backslash ignores remaining text
var isTurnedOn = false; // This is known as commenting
/* Commenting varies from language to language, this usage will ignore all text
within the outside characters. */ |
String (Often shortened to str)
A string contains any number of characters (letters, numbers, punctuation etc).
Usually these are used to contain and manipulate words or phrases. Most languages
reference a string with a set of quotes (""). Some languages
require that you specify the length of your string.
Example:
var UserName = "johnsmith";
var Password = "!turtle5"; // Strings can contain any characters
var PassQuestion = "What is your favorite food?"; // or phrases
var PassAnswer "bacon"; |
Integer (Often shortened to int)
An integer is any whole number, meaning any number without a decimal point.
Once you have a variable containing an integer, it is very easy to perform basic
arithmatic such as addition or multiplication. Integers can be both positive and
negative in most programming languages. Some languages require that you specify
the maximum value or number of characters in your integers.
Signed Numbers
When using most newer languages, it is not important to worry about signed
numbers. In cases where it is applicable, signed numbers are integers that
take the value's positive or negative sign into effect. If you don't specify
an integer as unsigned, the default is signed.
Unsigned Numbers
Unsigned numbers can only be absolute, meaning they can not use a negative
value. The only real benefit to using an unsigned number is that the maximum
range for the integer's value is about double. Considering that an unspecified
length signed number's maximum range is well over plus or minus two million, unsigned
numbers are usually not prefered.
Example:
var ApplesCollected = 5;
var ApplesNeeded = 10;
var ApplesRemaining = ApplesNeeded-ApplesCollected;
/* This will find the difference between the two values */ |
Floating Point (Often shortened to float or real)
A floating point number is any number with a decimal point. Some programming
languages do not distinguish between Integers and Floating Point numbers and default
to integer.
Example:
var PurchaseSubtotal = 45.37; (dollars)
var SalesTax = 0.10; (percent)
var PurchaseTotal = PurchaseSubtotal+ (PurchaseSubtotal*SalesTax);
/* * (asterisk) is used for multiplication */ |
Pointer
Some programming languages require you to specify an area in the computer's
hard disk or RAM(random access memory) to delare an variable. A pointer contains the address in memory where the value for a variable can be found.
The use of this mechanic is somewhat unintuative, and will not be found in newer
languages. |
|
|
Previous Page:
Introduction,
Next Page:
Arrays. |
|