8.1. Compound values¶
Most of the data types we have been working with represent a single
value—an integer, a floating-point number, a boolean value.
string
s are different in the sense that they are made up of
smaller pieces, the characters. Thus, string
s are an example of a
compound type.
Depending on what we are doing, we may want to treat a compound type as a single thing (or object), or we may want to access its parts (or instance variables). This ambiguity is useful.
It is also useful to be able to create your own compound values. C++ provides two mechanisms for doing that: structures and classes. We will start out with structures and get to classes in Section 14 (there is not much difference between them).
Before you keep reading...
Making great stuff takes time and $$. If you appreciate the book you are reading now and want to keep quality materials free for other students please consider a donation to Runestone Academy. We ask that you consider a $10 donation, but if you can give more thats great, if $10 is too much for your budget we would be happy with whatever you can afford as a show of support.
- integer
- Try again!
- string
- Correct!
- floating-point number
- Try again!
- boolean value
- Try again!
Q-3: Which is different from the others because it is does not represent a single value?