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 ruleintcan store any positive or negative number within the limits of your chosen language. - long:
The
longdata type is used to store a larger number thanintcan store (if your programming language has a limit). It is important note that alongdata type is normally a 64 bit memory address as opposed tointwhich is normally a 32 bit memory address. With that in mindlongshould only be used when anintis not adequate. - float:
The
floatdata type is used to store floating point numbers or numbers with a decimal value. Some examples of what we can store in afloatcould be:1.2,24.57, or27894.02832. Some programming languages handlefloatdifferently, but a good general rule is that you won't be able to directly convert afloatdata 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 afloatdata type. For a bigger number most languages that have a limit onfloatwill also havadoubledata type. - double:
The
doubledata type is used like to store a larger value number thanintcan 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 adoubledata type it is a 64 bit memory address as opposed tointorfloatwhich is normally a 32 bit memory address. With that in mind adoubleshould only be used when anintorfloatis adequate. - char:
The
chardata 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 thechardata type differently but a good general rule to follow is thatcharcan 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 thechardata type with a single quote:'e'. It is important to note that although you can store digits in achardata 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
stringdata type, sometimes referred to asString, can be thought of as a "string" (pun intended) ofchardata types. Again some programming languages treatstringdifferently 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 astringwith double quotes:"This is a string!". - bool or boolean:
The
booldata type, sometimes referred to asboolean, can be thought of as a data type that is either true or false. Although every programming language can treatbooldifferent most of them allow you to store eithertrue,false,1, or0, with1being treated as true and0being treated as false.