Data Types
In programming data types, also sometimes referred to as types, are the types of data that the language can interprete. Every language can potentially, and more than likely will, support other data types but this guide is going to go over the most basic types that are used by most programming languages.
Some of the most common data types are the following:
- int or integer:
The
int
, sometimes also referred to asinteger
, data type is used to store numeric values. Some languages have a maximum value this data type can store but as a general ruleint
can store any positive or negative number within the limits of your chosen language. - long:
The
long
data type is used to store a larger number thanint
can store (if your programming language has a limit). It is important note that along
data type is normally a 64 bit memory address as opposed toint
which is normally a 32 bit memory address. With that in mindlong
should only be used when anint
is not adequate. - float:
The
float
data type is used to store floating point numbers or numbers with a decimal value. Some examples of what we can store in afloat
could be:1.2
,24.57
, or27894.02832
. Some programming languages handlefloat
differently, but a good general rule is that you won't be able to directly convert afloat
data type to an int without rounding the value to the nearest whole number although some programming languages may do this for you automatically. Another tip to note is that most languages that do have a limit on how much information can be stored in afloat
data type. For a bigger number most languages that have a limit onfloat
will also havadouble
data type. - double:
The
double
data type is used like to store a larger value number thanint
can store (if your programming language has a limit) and normally also supports decimal values like afloat
. Its important to note that most of the time if a programming language has adouble
data type it is a 64 bit memory address as opposed toint
orfloat
which is normally a 32 bit memory address. With that in mind adouble
should only be used when anint
orfloat
is adequate. - char:
The
char
data type is used to store a single character. Some programming languages don't have a specific data type for characters and instead opt to just support strings. Every programming language can potentially handle thechar
data type differently but a good general rule to follow is thatchar
can contain a single character that can be letters (upper and lower case), a numerical digit, or common punctuation marks (.
or-
). Most commonly programming languages denote thechar
data type with a single quote:'e'
. It is important to note that although you can store digits in achar
data type you will not be able to do calculations with it in most programming languages as you are actually storing a charater of say5
, not a value of5
. - string or String:
The
string
data type, sometimes referred to asString
, can be thought of as a "string" (pun intended) ofchar
data types. Again some programming languages treatstring
differently and have different limits as to what can be stored in astring
. A good general rule for strings is that it can support whatever your language of choices supports forchar
. Most commonly programming languages denote astring
with double quotes:"This is a string!"
. - bool or boolean:
The
bool
data type, sometimes referred to asboolean
, can be thought of as a data type that is either true or false. Although every programming language can treatbool
different most of them allow you to store eithertrue
,false
,1
, or0
, with1
being treated as true and0
being treated as false.