User Defined Data Types
- This is chapter 10 in your book, you should read it.
- In the 130 you learned about a number of atomic or simple data types.
- They are called atomic because they can not be broken into any smaller components.
- Look at these types.
-
- What are these different types?
- This is actually a subset of the types.
- See this page for more details.
- What is the domain of each of these types?
- Look in /usr/include/limits.h
- A character is 8 bits.
- A character can then represent
- Signed:
- $ -2^{(8-1)} $ to $2^{(8-1)}-1 $
- or $ -2^7$ to $2^7-1 $
- or -128 to 127
- Unsigned:
- Why does unsigned exist?
- 0 to $ 2^{8}-1 $
- or 0 to 255
- Look at char.cpp
- note when we compile this, the compiler warns us that this is a bad idea.
- sizeof gives the size of a type or expression in bytes
- This returns a size_t.
- A size_t is probably an unsigned int or long.
- But it is a positive number
- Why does this exist?
- What are the operations on each of these types?
- See the bottom of the page of this reference.
- Or appendix B of your book.
- What are the relationships between the various sub types of a given type?
- We know that a char is a byte. (by definition)
- This is at least 8 bits.
- But could be larger based on the architecture of the system
- The standard says that a short is at least as big as a char, but perhaps longer.
- sizeof(long long) >= sizeof(long) >= sizeof(int) >= sizeof(int) >= sizeof(short) >= sizeof(char) >= 8.
- Look at sizes.cpp
- What type form the above chart are we missing?
- enum : an enumerated type
- More on this in just a bit.
- We will expand on the basic types the rest of the semester
-
- From Page 490
- What types that we know about are missing from this chart?
- Character Math
- Characters are an integer type.
- We can do math on them.
- One of the really nice properties of the ASCII, and the UNICODE table in general is the structure.
- The value for 0 is 48
- The value for 1 is 49
- The value for 2 is 50
...
- They are all sequential.
- Thus if we have an ascii digit, we can convert it to it's "integer" value by subtracting '0'
- The ascii code for '7' is 55.
- The ascii code for '0' is 48.
-
'7' - '0' = 55 - 48
= 7
- This is true for the lower case letters and the upper case letters as well.
- What is 'a'+3?
- What is 'X'-2?