Data Types help determine how the value will be stored in memory and what can be done to the value.
Type | Description | Values | Can't |
---|---|---|---|
int | a whole number (Integer) | 0, 5, 3000, -456 | have a fractional part such as 0.0,3.14,5.6789 |
float | 6 to 7 digits | 1.23456 | |
double | 15 to 16 digits if required for more precision. Will use more memory. | 1.234567890 | |
bool | used to make decisions in code | true or false |
Example: Integers can be added such as 3+5, but Integers can’t have fractionals such as 3+5.5
To put this into practice, let’s declare a variable
int main()
{
int numberOfDeathStars; // decalared a variable
numberOfDeathStars = 1; // variable has been initalized
// = is an assignment operator
// so now numberofDeathStars has been initalized with the value of 1
}