Chapter 8

A1: Short, non-recursive functions that can fit in one line of code.
A2:
  1. void song(char * name, int times = 1);

  2. None. Only prototypes contain the default value information.

  3. Yes, providing you retain the default value for times:

      void song(char * name = "O, My Papa", int times = 1);
    
A3: You can use either the string "\"" or the character `"` to print a quotation mark. The following functions show both methods:
#include <iostream.h>
void iquote(int n)
{
    cout << "\"" << n << "\"";
}

void iquote(double x)
{
    cout << `"` << x << `"`;
}

void iquote(const char * str)
{
    cout << "\"" << str << "\"";
}
A4:
  1. This function shouldn't alter the structure members, so use the const qualifier.

     void show_box(const box & container) { cout << "Made by " << ...

Get The Waite Group's C++ Primer Plus, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.