Engineering Problem Solving with C++, 3e Chapter 9 Test Bank
1. Write the C++ statement that will correctly declare a pointer variable ptr, which has base
3. List two of the common errors that occur when using dynamic memory.
4. Draw a picture which will show how the value 15 is inserted into the following linked list
after the value 10, by drawing the arrows needed and crossing out the arrows which are
5. Write the steps that would occur when the value 17 is removed from the following linked list.
head
6. Declare an object that is a list of integers, and another object which is an iterator for that list.
7. Write the statements that will dynamically allocate an array of nine integers, storing the
starting address into pointer myArrPtr, and then the statement which will release that
dynamically allocated array.
8. Which of the following is the address of operator?
9. Which of the following is the scope resolution operator?
10. Which of the following is the dereference operator?
11. The operand for the & operator can be
Ω
Engineering Problem Solving with C++, 3e Chapter 9 Test Bank
12. Using he following C++ statements which option correctly describes the result of the
statement a = *ptr;
int a(6), b(9), *ptr(&b);
a = *ptr;
A. The value of variable a is changed to the value of variable b.
B. The value of variable b is changed to the value of variable a.
C. The value of variable ptr is changed to point to the address of variable a.
D. The address of variable a is changed to the address of variable b.
13. Given the following declaration which of the statements given in the options is not a valid
C++ statement.
int x(5), y(7), *ptr1(&x), *ptr2(&y);
14. Using the statement double *ptr, x[6]={1.5, 2.2, 4.3, 7.5, 9.1, 10.5}; which of the following
statements is not a valid statement.
15. The address of an object is the same from one execution to the next execution.
16. A pointer is a variable which holds an address as its value.
17. When pointer variable ptr1 is declared to have base type double and initialized, the statement
ptr1++; changes the value of ptr1 by adding one to the address in ptr1.
18. Pointer references to array values are based on the knowledge that memory assignment of
array values is always sequential.
A. True B. False
19. An array variable can be passed to a pointer parameter.
A. True B. False
20. The declaration const char *c_ptr=”try this”; means that the value of c_ptr can not be
changed in other words c_ptr can not point to some other string.
A. True B. False
21. The declaration char const *cptr =”another phrase”; is an invalid statement because the
keyword const is in the wrong place.
A. True B. False
22. Dynamic memory is allocated from a region of the program’s memory called the heap.
A. True B. False
23. A memory leak occurs when you fail to delete dynamically allocated memory when it is not
longer needed.
A. True B. False
24. The pop operation will remove the least recently added element from a stack.
A. True B. False
25. A queue is a (FIFO) data structure.
A. True B. False
26. Dereferencing a pointer to a type results in an object of that type.
A. True B. False
27. The size of a pointer depends of its base type.
A. True B. False
28. A pointers base type determines how the object referenced by the pointer will be interpreted.
A. True B. False
29. Which of the following are supported operators for pointer arithmetic in C++.
A. +
B. C. ++
D. All of these are supported.
30. A pointers base type defines pointer arithmetic.
A. True B. False
31. Show the output generated by the following code segment. Assume all necessary header
files have been included.
32. A stack is a (FIFO) data structure.
A. True B. False