Numeric Types
- There are two basic numeric types in c/c++
- Integer types
- Floating point or real number types.
- Integer types
-
int
is the basic type.
- This represents numbers between INT_MIN and INT_MAX
-
#include <climits>
for these and all other constants in this section.
- Unfortunately this is not fixed in the standard.
- So as the hardware changes, this value can change with it.
- See /usr/include/limits.h
- This is the workhorse for integer types. Prefer this to others.
-
int
can be modified by the following
-
signed
and unsigned
-
signed
is the default and is probably never needed.
- It means the number can be positive or negative.
-
unsigned
- means the values are 0 ≤ n ≤
UINT_MAX
.
- UINT_MAX is probably twice INT_MAX.
- You use this when you need more positive numbers and your value can never be negative.
-
short
or long
- are essentially smaller and larger versions of an int.
- Currently short is 16 bits and ling is 64 bits.
- But this changes.
- These are for special use.
- Can be modified with
signed
and unsigned
- Can be modifiers for
int
but that is not needed.
-
long long
is a special that is as big as gets supported.
- The type
char
is also an integer type.
- This is confusing at first.
- Remember, everything is stored as a number.
- Characters are stored as their ASCII representation.
- Look at the ASCII table.
- We can do math on char type.
- But it is printed as the character, not the number.
- We will look at this more later.