entry: numerical data types in C
This commit is contained in:
parent
57c270d299
commit
d91e1652ba
1 changed files with 55 additions and 0 deletions
55
zk/Numerical_data_types_in_C.md
Normal file
55
zk/Numerical_data_types_in_C.md
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
---
|
||||
tags:
|
||||
- C
|
||||
---
|
||||
|
||||
# Numerical data types in C
|
||||
|
||||
## Summary
|
||||
|
||||
| Data type | Memory | Examples |
|
||||
| --------------- | ------- | -------------- |
|
||||
| `int` | 4 bytes | `0`, `-3`, `9` |
|
||||
| `short int` | 2 bytes | `0`, `-3`, `9` |
|
||||
| `long int` | 4 bytes | `0`, `-3`, `9` |
|
||||
| `long long int` | 8 bytes | `0`, `-3`, `9` |
|
||||
| `float` | 4 bytes | `2.1882` |
|
||||
| `double` | 8 bytes | `2.18829801` |
|
||||
|
||||
## `int`
|
||||
|
||||
An `int` can hold a signed or unsigned value or 0 but it cannot hold a decimal
|
||||
value.
|
||||
|
||||
On most modern systems, an `int` typically allocates 4 bytes (32 bits) of
|
||||
memory. This is not always the case however and some systems may allocate only 2
|
||||
bytes.
|
||||
|
||||
$2^32 = 4294967296$ thus for signed ints this provides a range -2,147,483,648 to
|
||||
2,147,483,647. For unsigned ints this provides a range 0 to 4,294,967,295.
|
||||
|
||||
## `short int`
|
||||
|
||||
The same properties of `int` but a smaller bit allocation - 2 bytes (16bits).
|
||||
|
||||
$2^16 = 65536$ thus for signed short ints this provides a range -32,768 to
|
||||
32,767. For unsigned short ints this provides a range 0 - 65, 536.
|
||||
|
||||
## `long int`
|
||||
|
||||
Basically the same as `int` but you are guarenteed 4 bytes, independent of
|
||||
system.
|
||||
|
||||
## `long long int`
|
||||
|
||||
An extra-long `int` allocated 8 bytes (64bits).
|
||||
|
||||
## `float`
|
||||
|
||||
Use to hold decimal values. Allocated 4 bytes (32 bits) of memory. Holds less
|
||||
precision than a `double` but uses less memory.
|
||||
|
||||
## `double`
|
||||
|
||||
Use to hold decimal values. Allocated 8 bytes (32 bits) of memory. Provides
|
||||
greater precision than a `float` but uses more memory.
|
||||
Loading…
Add table
Reference in a new issue