int *p;
int num;
Assume that memory location 1200 is allocated for p and memory location 1800 is
allocated for num.
1. The statement p=# stores the address of num that is, ____ into p.
a. 1800
b. 24
c. 1200
d. num
2. You can initialize a pointer variable by setting it to ____
a. 0
b. NULL
c. 1
d. a or b
Consider the following lines of code:
struct studentType
{
char name[27];
double gpa;
int sID;
char grade;
};
int *p;
double *q;
char *chPtr;
studentType *stdPtr;
3. The statement “stdPtr++” increments the value of stdPtr by ____ bytes.
a. 10
b. 20
c. 40
d. 80
4. An array created during the execution of a program is called a ____ array.
a. static
b. final
c. just in time
d. dynamic
vector<int> v (1, 2);
int value = v.pop_back ();
cout << value << endl;
5. What is the output of the code fragment above?
a. 0
b. 1
c. 2
d. There is no output
int exampleRecursion (int n)
{
if (n==0)
return 0;
else
return exampleRecursion(n-1) + n*n*n;
}
6. What is the output of exampleRecursion(0)?
a. 0
b. 3
c. 9
d. 27
7. Which of the following statements is NOT true about infinite recursion?
a. In theory, infinite recursion executes forever.
b. In reality, infinite recursion will lead to a computer running out of
memory and abnormal termination of the program.
c. Functions that are indirectly recursive always lead to infinite
recursion.
d. If recursive calls never lead to a base case infinite recursion occurs.
int func3(int m, int n) {
if (m < n)
return 0;
else
return 1 + func3(m-n, n);
}
8. What is the value of func3(6, 3), based on the code above?
a. 2
b. 3
c. 6
d. 9
9. Which of the following operations is needed for a linear implementation of a
stack but not a linked implementation?
a. isEmptyStack
b. isFullStack
c. initializeStack
d. destroyStack
10. What is the equivalent infix expression for the postfix expression n m + p * ?
a. p * n + m
b. m + (p * n)
c. (n + m) * p
d. n + m * p
11. The function addQueue does which of the following?
a. adds all the contents from one queue to another
b. appends one queue to the back of another
c. adds a new element to the front of the queue
d. adds a new element to the rear of the queue
[0] [1] [2] [3] [4] [5] [6] [7]
list 35 12 27 18 45 16 38 …
12. What is the minimum number of comparisons that have to be made to find 18
using sequential search on the list above?
a. 1
b. 2
c. 3
d. 4
13. If we want to design a search algorithm that is of an order less than log2n,
then it ____ be comparison based.
a. must
b. could
c. cannot
d. should
14. Selection sort can be applied to which of the following?
a. arrays
b. linked lists
c. stacks
d. a and b
15. Quick sort uses ____ for implementation.
a. recursion
b. traversal
c. heaps
d. queues
16. The listing of the nodes produced by the preorder traversal of a binary tree is
called the ____ sequence.
a. inorder
b. preorder
c. postorder
d. None of the above