C++ Quiz
C++ Quiz
Review Questions
1. Define Overflow.
2. Can you have overflow with integer calculations?
3. Define Underflow.
4. Can you have underflow in integer calculations?
5. Whats the biggest floating point number that can be represented on your machine.
6. On your pocket calculator what does 1-(1/3)-(1/3)-(1/3) equal?
7. Why do you never want to use floating point for money?
Page 22
Chapter 20: Advanced Pointers
A race that binds
Its body in chains and calls them Liberty,
And calls each fresh link progress
Robert Buchanan
Review Questions
1. Define Linked List.
2. What would you use a linked list for?
3. Define Double-linked List.
4. What can a double-linked list be used for that a linked list cannot.
5. Define binary tree.
6. What are trees good for?
7. How would you delete an element from a tree?
Page 23
Chapter 21: Advanced Classes
The ruling ideas of each age have ever been the ideas of its ruling class
Karl Marx
Manifesto of the Communist Party
Review Questions
1. Define derived class.
2. Define base class.
3. Can a class be both derived and base?
4. Define virtual function.
5. Define pure virtual function.
6. Describe how to implement virtual functions using function pointers. (This is what C++ does
internally.)
7. Define abstract class.
8. Why cant you use an abstract class to define a variable?
Page 24
Chapter 22: Exceptions
How glorious it is and also how painful to be an exception
Alfred De Musset
Review Questions
1. Define exception.
2. Define try.
3. Define catch.
4. Define throw.
Page 25
Chapter 23: Modular Programming
Many hands make light work
John Heywood
Review Questions
1. Define header file.
2. What should go in a header file? Why?
3. What should not go in a header file? Why?
4. Define extern.
5. Define static. (Warning: Its used for a lot of things.)
6. Define infinite array.
Page 26
Chapter 24: Templates
Thou cunningst pattern of excelling nature,
Shakesphere, Othello Act V
Review Questions
1. Define template.
2. When does a template cause code to be generated?
3. What is a function specialization?
4. What is a class specialization?
5. Define "export"?
6. Name a compiler which implements the "export" directive correctly.
Page 27
Chapter 25: Standard Template Library
Goodness and evil never share the same road, just as ice and charcoal never share the same container.
Chinese proverb
Review Questions
1. Define STL Container.
2. What are the differences between a STL vector and a C++ array?
3. How do you check to see if an iterator has reached the end of a container?
4. What's stored in a map?
Page 28
Chapter 26: Program Design
If carpenters made houses the way programmers design programs, the first woodpecker to come along would destroy all of
civilization
Traditional computer proverb
Review Questions
1. Name and define three design goals that should be a part of any program's design.
2. What are other design factors that might be considered.
3. MS/DOS was designed for a 640K PC with 360K floppies as it's primary storage device. Did
the design of the operating system make it easy to expand the system for today's modern
computers?
4. What makes a good module?
5. What is information hiding?
6. Why are global variables considered bad?
7. Are all global variables bad?
8. One of the problems with C++ is that a class must expose implementation information to
modules using that class. Where is this implementation information located?
Page 29
Chapter 27: Putting It All Together
For there isnt a job on the top of the earth the beggar dont know, nor do
Kipling
Review Questions
1. Describe the programming process used to create the program created in this chapter. Explain
what worked and what didnt. If something didnt work, what can be done to fix the problem?
Page 30
Chapter 28: From C to C++
No distinction so little excites envy as that which is
derived from ancestors by a long descent
Franois De Saliganc De La Mothe Fnelon
Review Questions
1. Define K&R Style Functions.
2. Define malloc.
3. Define free.
4. Why should you never use malloc on a class?
5. Why should you never use free on a class?
6. How do you initialize a structure to be all zeros? How do you initialize a class to be all zeros?
7. Define setjmp and longjmp.
8. What are the dangers associated with using these functions?
Page 31
Chapter 29: Programming Adages
Second thoughts are ever wiser
Euripides
No review questions
Page 32
Supplement: From C to C++
New nobility is but the act of power, but ancient nobility is the act of time
Francis Bacon
Review Questions
1. Why are comments required in a program?
2. Why must you write comments before or while you write the program, never after?
3. Which is better: 1) The underscore method of writing names example: this_is_a_var, or
the upper/lower case method: ThisIsATest? (Note this is a religious issue and has no right
answer.)
4. Define std::cout and use it in a C++ statement.
5. Define the following:
long int short int unsigned signed
float double register auto
volatile const reference extern
6. Why must you use the notation int(very_short) to write a very short number (aka. a
character variable)? What would happen if you wrote it out without the int wrapper?
7. Define side effect.
8. Why are side effects bad things.
9. When is the following variable created, initialized and destroyed?
int funct(void) {
int var = 0 // The variable in question
// ......
10. When is the following variable created, initialized and destroyed?
int funct(void) {
static int var = 0 // The variable in question
// ......
11. When is the following variable created, initialized and destroyed?
int var = 0 // The variable in question
int funct(void) {
// ......
12. Define reference?
13. What is binding and when does it occur?
Page 33
14. What is the difference, if any, between the type of values returned by the following two
functions:
int func1(void)
const int funct2(void)
15. What is the difference, if any, between the type of values returned by the following two
functions:
int &fun1(void)
const int &fun2(void)
16. Which parameters in the following function can be modified inside the function:
void fun(int one, const int two, int &three, const int &four);
17. In the previous question, which parameters when changed will result in changes made to the
callers variables?
18. Which parameters in the following function can be modified inside the function:
void fun(int one[], const int two[]);
19. In the previous question, which parameters when changed will result in changes made to the
callers variables?
20. Define Dangling Reference.
21. Why are dangling references a bad thing?
22. Can we overload the square function using the following two function definitions?
int square(int value);
float square(float value);
23. Can we overload the square function using the following two function definitions?
int square(int value);
float square(int value);
24. Define default parameters.
25. What does the keyword inline do?
26. What programming technique was used to solve the calculator problem of Chapter 7, The
Programming Process.
Page 34