Difference between revisions of "Basic data types"
(Created page with "C++ contains many data types, the '''basic data types''' (also '''fundamental''' or '''primitive''') are those which are built into the core language. More complex data types...") |
|||
Line 4: | Line 4: | ||
==<code>int</code>== | ==<code>int</code>== | ||
− | The <code>int</code> data type is used for representing positive and negative integers (whole numbers). Typically an <code>int</code> uses 4 bytes (32 bits) of storage. The first bit of an <code>int</code> is used for the sign (positive or negative) and the remaining 31 bits are used to encode the integer in binary. Thus, the typical range of an <code>int</code> is < | + | The <code>int</code> data type is used for representing positive and negative integers (whole numbers). Typically an <code>int</code> uses 4 bytes (32 bits) of storage. The first bit of an <code>int</code> is used for the sign (positive or negative) and the remaining 31 bits are used to encode the integer in binary. Thus, the typical range of an <code>int</code> is -2<sup>31</sup> to 2^<sup>31</sup> - 1</math>. Note that the positive range is - 1 because of the representation of zero is included in the positive numbers but there is no "negative zero". |
==<code>double</code>== | ==<code>double</code>== | ||
==<code>char</code>== | ==<code>char</code>== | ||
==<code>bool</code>== | ==<code>bool</code>== |
Revision as of 22:30, 20 January 2018
C++ contains many data types, the basic data types (also fundamental or primitive) are those which are built into the core language. More complex data types are typically built upon the foundation of these basic data types.
The most common basic data types are int
, double
, char
, and bool
.
int
The int
data type is used for representing positive and negative integers (whole numbers). Typically an int
uses 4 bytes (32 bits) of storage. The first bit of an int
is used for the sign (positive or negative) and the remaining 31 bits are used to encode the integer in binary. Thus, the typical range of an int
is -231 to 2^31 - 1</math>. Note that the positive range is - 1 because of the representation of zero is included in the positive numbers but there is no "negative zero".