1. | a reference parameter, | a copy of the value, | reference to the original value, |
2. | automatically invoked, | goes out of scope, | a destructor, |
3. | const modifier, | a parameter declaration, | not change the value, |
4. | dangling pointer, | a pointer, | deallocated memory, |
5. | header file, | a program, | an #include statement, |
6. | ifstream and ofstream, | define streams, | manipulate files, |
7. | initialize, | an object, | declared, |
8. | iostream library, | manipulators, | stream insertions and extractions, |
9. | not been deallocated, | no pointer points, | a memory leak, |
10. | reused, | the declarations, | occur in different scopes, |
11. | sequence of characters, | a string object, | a terminating '\0' character, |
to complete the following sentences
__________
is __________
that points to __________
.
__________
is incorporated into __________
using __________
.
__________
when an object __________
is called __________
.
__________
__________
when it is __________
.
__________
, but to which __________
is called __________
.
__________
as long as __________
associated with the names __________
.
__________
defines __________
for specifying how to perform __________
.
__________
that constitute __________
does not include __________
.
__________
__________
that __________
.
__________
passes a __________
instead of a __________
..
Each underscore __________
represents a phrase; phrases are assigned to blanks in
the left-to-right order given in the triple. Each triple is used at most once;
note that there is one more triple than sentences (that is, there will be one
triple set that doesn't get used).
#include
statement. (triple 5)
string
object does not include a terminating '\0'
character. (triple 11)
i = object.method1().method2();
method1()
's return type.
The first fact is that object.method1()
must return an object (class or
struct) because it's used as the left operand of a dot accessor:
( object.method1() ) . method2()
object.method1()
must contain a
method function named method2()
because that's the right operand of the
dot accessor.
int * ip = new int(1);
delete ip;
delete *ip;
The tip your colleage should remember that delete
always deletes values of
type pointer; it is syntatically incorrect to delete a value of any other type.
Using this tip, your colleague's quandry becomes easy to resolve: ip
is a
value of type pointer (to int
), so delete ip
is correct. *ip
is
a value of type int
, which is not a pointer (pace C++'s idiot
implicit conversions), so delete *ip
is incorrect.
void print_ident(void) { int x = 3 int ident[x, x] = { 0 }; for (int i = 1; i <= 3; i++) ident[i, i] = 1; for (int i = 1; i <= 3; i++) { for (int j = 1; i <= 3; j++) cout << ident[i, j] << " "; cout << '\n'; } }
Alas, practically every line in this program is wrong:
void print_ident(void) { int x = 3 // no semicolon int ident[x, x] = { 0 }; // syntax is [x][x]; x is not a constant. for (int i = 1; i <= 3; i++) // index range is 0 <= i < 3. ident[i, i] = 1; // [,] syntax again for (int i = 1; i <= 3; i++) { // index range again for (int j = 1; i <= 3; j++) // index range again cout << ident[i, j] << " "; // [,] syntax again cout << '\n'; // ok } }
This page last modified on 27 August 2001.