Next, we will look at built-in data types. All but the most trivial programs
store and manipulate information on a computer. In your GENE 121 and MTE 140 courses,
you learned how to store and manipulate data using C++. This is just a quick
review of those features that overlap between C and C++, starting with
variables.
To store information on a computer, it is ultimately necessary to convert the
data into ones and zeros: a novel is converted into unicode characters, each of which
is made up of sixteen bits while a photograph is approximated using a discretizations which
is then approximated using the Fourier cosine transform, the coefficients of which
are stored on the computer.
There are fewer than two dozen built-in data types: formats for information for
which the library is already aware: these are to store characters, integers on restricted
ranges, memory-related and real numbers on restricted ranges with restricted precision.
bool 8 bits
char | 8 bits | 0 to 256 |
signed char | 8 bits | -128 to 127 |
A special wide character is available in the library wchar.h and the type
is wchar_t. It is used for unicode characters.
short | 16 bits | -32768 to 32767 |
unsigned short | 16 bits | 0 to 65535 |
int | 32 bits | -2147483648 to 2147483647 |
unsigned int | 32 bits | 0 to 4294967295 |
long | 64 bits | -9223372036854775808 to 9223372036854775807 |
unsigned long | 64 bits | 0 to 18446744073709551615 |
long long | 64 bits | -9223372036854775808 to 9223372036854775807 |
unsigned long long | 64 bits | 0 to 18446744073709551615 |
float | 32 bits |
double | 64 bits |
long double | 128 bits |
size_t | 64 bits | 0 to 18446744073709551615 |
ptrdiff_t | 64 bits |