Integers
- Integer types represent the mathematical integer values
- ... -3, -2, -1, 0, 1, 2, 3, ...
- Both signed and unsigned.
- But the ... on either end is a problem
- What does ... mean?
- Why might we not be able to do this in a computer?
- Think about a football score board
-
- What is the "highest" score you can have in the game
- In theory?
- According to the scoreboard?
- This is a representation problem.
- There is not enough space on the scoreboard
- Are there scoreboards with more spaces?
- When C was invented, memory was expensive
- So they created a bunch of different classes of integers.
- If you know your values will be small, you can use a
char
or short
.
- If you know you want the biggest numbers available, use an
unsigned long
.
- But
int
it just right for most things.
- Since the power and abilities of computers changes over the years, the standard does not set values, but properties
- A
short
is at least as big as a char
- A
int
is at least as big as a short
- And so on.
- And you can find get constants for the max values
-
#include <climits>
- Look at
/usr/include/limits.h
- Look at
/usr/include/c++/12/climits
- Take a look at intDemo.cpp
- When you go beyond the size it is called integer overflow
- And sometimes integer underflow
- Take a look at intDemo.cpp