Sei sulla pagina 1di 407

1.

Which of the following Visual C++ objects are contained within a "Project"?
Files
Visual C++ Solutions
Flow charts

(a) II only
(b) I, II and III
(c) I only
(d) II and III only
Correct answer is (c)

-------------------------------------------------------------------------------2.
Integrated programming environments make it difficult to mix and match tools fr
om different sources. This is
(a) good, because tools from different sources cannot be made to interact with
each other
(b) good, because it ensures compilation is not done incrementally by accident
(c) bad, because all the tools will then have the same user interface
(d) bad, because no single vendor is likely to be the source of all the best to
ols
Correct answer is (d)

-------------------------------------------------------------------------------3.
When debugging using Visual C++, which of the following are possible through th
e Watch window?
The program's execution can be stopped.
The value of an arbitrary C expression can be calculated.
The value of a program variable can be set.

(a) II only
(b) II and III only
(c) III only
(d) I, II, and III.
Correct answer is (b)
Your score on this question is: 0.00

Feedback:
See section 1.2.3 of the course notes.
-------------------------------------------------------------------------------4.
When using a debugger to find the cause of a program's incorrect behavior,
(a) it is often necessary to start the program multiple times under the debugg
er
(b) the program is usually executed to the point at which the behavior occurs a
nd then executed backwards to find the cause
(c) it is fastest to start by stopping the debugger long before the behavior ap
pears
(d) the faulty code fragment must first be identified
Correct answer is (a)
Your score on this question is: 0.00
Feedback:
See section 1.2.4 of the course notes.
-------------------------------------------------------------------------------5.
Consider the following program.
int i;
int * jp = &i;
int main(int i, char * argv[]) {
printf("%d %d\n", (int) &i, (int) jp);
}
Which of the following describes what it prints?
(a) nothing: it will not compile because it is ambiguous
(b) two integers that are exactly the same
(c) two very different integers
(d) two values, one 4 greater than the other
Correct answer is (c)
Your score on this question is: 0.00
Feedback:
See section 1.4.1 of the course notes.
-------------------------------------------------------------------------------6.
What is printed as a result of execution of the following program?
#include <stdio.h>
void callee(int * count) {
(*count)++;
}

int main (int argc, char *argv[]) {


int count = 4;
callee(&count);
printf("%d", count);
return 0;
}

(a) 4
(b) It cannot be determined from the information given.
(c) 8
(d) 5
Correct answer is (d)
Your score on this question is: 7.14
Feedback:
See section 1.4.1 of the course notes.
-------------------------------------------------------------------------------7.
What does the following program print?
void callee(int * count) {
(*count)++;
}
int main (int argc, char *argv[]) {
int count = 4;
callee(count);
printf("%d", count);
return 0;
}

(a) 5
(b) nothing: it will not compile successfully
(c) 8
(d) 4
Correct answer is (b)
Your score on this question is: 7.14
Feedback:
See section 1.4.1 of the course notes.
-------------------------------------------------------------------------------8.
Consider the following program.
int i;
int j = 1;
int callee(int number) {
int plusone;

plusone = number + 1;
return plusone;
}
int main (int argc, char *argv[]) {
if (j == 1) return callee(i);
return j;
}
Which of the following are allocated in the activation record immediately after
the function callee() is invoked?
(a) plusone and number only.
(b) i only.
(c) plusone only.
(d) i, j and number only.
Correct answer is (a)
Your score on this question is: 0.00
Feedback:
See section 1.4.2 of the course notes.
-------------------------------------------------------------------------------9.
The Visual C++ Memory window displays
(a) the contents of memory, interpreted as 32-bit integers, without the associ
ated variable names
(b) the names and values of variables in memory, interpreted as 32-bit integers
no matter what the variables' types
(c) the contents of memory, interpreted in one of several ways, without the ass
ociated variable names
(d) the names and values of variables in memory, interpreted in one of several
ways
Correct answer is (c)
Your score on this question is: 7.14
Feedback:
See section 1.3.3 of the course notes.
-------------------------------------------------------------------------------10.
In a computer in which both addresses and integers are 32 bits wide, how many b
ytes of memory will the compiler allocate for following code fragment?
int a;
int * b = &a;

(a) 32

(b) 4
(c) 0
(d) 8
Correct answer is (d)
Your score on this question is: 7.14
Feedback:
See section 1.3.2 of the course notes.
-------------------------------------------------------------------------------11.
Which of the following
chine code generated by
The resulting code will
The resulting code will
The resulting code will

are true of the effect that optimizations have on the ma


compilers?
be faster and/or smaller.
be clearer.
be harder to debug.

(a) I and II only


(b) I only
(c) I, II, and III
(d) I and III only
Correct answer is (d)
Your score on this question is: 0.00
Feedback:
See section 1.5.3 of the course notes.
-------------------------------------------------------------------------------12.
Which of the following computations may be performed by exactly one CPU instruc
tion?
a = 5;
a = b + c * 5;
for (i = 0; i < 10; i += a[i++]);

(a) I, II, and III


(b) I only
(c) II only
(d) I and II only
Correct answer is (b)
Your score on this question is: 7.14
Feedback:
See section 1.5.1 of the course notes.

-------------------------------------------------------------------------------13.
Programs compiled for an Intel Pentium processor do not execute properly on a S
PARC processor from Sun Microsystems because
(a) the memory of a SPARC CPU is numbered from top to bottom
(b) the operation codes understood by the two processors are different
(c) the assembly mnemonics for the same "opcode" are different in the two proce
ssors
(d) copyrights regarding code cannot be violated
Correct answer is (b)
Your score on this question is: 0.00
Feedback:
See section 1.5.1 of the course notes.
-------------------------------------------------------------------------------14.
Consider the following pseudo-instructions.
0x40B7D8 i = i - 1
0x40B7E0 branch-if-not-zero 0x40B7D8
Which of the following code fragments do the instructions encode?
if (i != 0) i = i -1;
while (--i);
do { i = i - 1; } while (i);

(a) I only
(b) II and III only
(c) III only
(d) II only
Correct answer is (b)

1.
Which of the following does a debugger do?
Analyze the source code to find programming errors.
Decode machine code generated by a compiler.
Stop execution of a program.

(a) I, II, and III.


(b) I and III only
(c) III only

(d) II and III only


Correct answer is (d)
Your score on this question is: 7.14
Feedback:
See section 1.1.3 of the course notes.

-------------------------------------------------------------------------------2.
The machine code generated from source code by a compiler
(a) executes more quickly than the source code
(b) does not preserve all the information given in the source code
(c) associates variable values with their names
(d) can be easily inspected to check the correctness of the compiler
Correct answer is (b)
Your score on this question is: 7.14
Feedback:
See section 1.1.3 of the course notes.
-------------------------------------------------------------------------------3.
When debugging using Visual C++, which of the following are possible through th
e Watch window?
The program's execution can be stopped.
The value of an arbitrary C expression can be calculated.
The value of a program variable can be set.

(a) II and III only


(b) I, II, and III.
(c) III only
(d) II only
Correct answer is (a)
Your score on this question is: 7.14
Feedback:
See section 1.2.3 of the course notes.
-------------------------------------------------------------------------------4.
In Visual C++, a Win32 Console Application is

(a) the status window of the Visual C++ environment


(b) a program that is able to control the operating system of a windows compute
r
(c) built by using sophisticated "Application Wizards"
(d) the simplest type of application Visual C++ can generate
Correct answer is (d)
Your score on this question is: 7.14
Feedback:
See section 1.2.1 of the course notes.
-------------------------------------------------------------------------------5.
Consider the function factorial() defined as follows.
int factorial(int n) {
if (n == 1) return n;
return n * factorial(n - 1);
}
How many activation records of factorial are allocated by invocation of the expr
ession factorial(4)?
(a) 0
(b) 1
(c) 4
(d) 5
Correct answer is (c)
Your score on this question is: 7.14
Feedback:
See section 1.4.2 of the course notes.
-------------------------------------------------------------------------------6.
What is printed as a result of execution of the following program?
#include <stdio.h>
void callee(int * count) {
(*count)++;
}
int main (int argc, char *argv[]) {
int count = 4;
callee(&count);
printf("%d", count);
return 0;
}

(a) 5
(b) 8

(c) 4
(d) It cannot be determined from the information given.
Correct answer is (a)
Your score on this question is: 7.14
Feedback:
See section 1.4.1 of the course notes.
-------------------------------------------------------------------------------7.
Activation records are organized in stacks because
(a) functions need to access all the variables of the functions that call them
.
(b) they are seldom needed during program execution.
(c) stacks allow activation records to be pushed and popped in any order.
(d) stacks are simple enough for the hardware to manage.
Correct answer is (d)
Your score on this question is: 0.00
Feedback:
See section 1.4.2 of the course notes.
-------------------------------------------------------------------------------8.
Consider the following program segment.
int factorial(int * arg) {
int n = *arg;
if (n == 1) return n;
return n * factorial(n - 1);
}
When the segment is executed, the variable n is allocated to
(a) just one address, and it is not known to the compiler
(b) many addresses none of which is known to the compiler
(c) many addresses that were chosen by the compiler
(d) just one address, and it was chosen by the compiler
Correct answer is (b)
Your score on this question is: 7.14
Feedback:
See section 1.4.1 of the course notes.
-------------------------------------------------------------------------------9.

In a computer in which both addresses and integers are 32 bits wide, how many b
ytes of memory will the compiler allocate as a result of the following pointer d
eclaration?
int * pointer;
(a) 4
(b) 0
(c) 64
(d) 8
Correct answer is (a)
Your score on this question is: 7.14
Feedback:
See section 1.3.2 of the course notes.
-------------------------------------------------------------------------------10.
Consider the following segment of a C program.
int i = 99;
int a[100];
i = a[i + 1];
Which of the following is true of the segment?
(a) When executed, the program will be prematurely terminated by the operating
system because of an illegal memory access.
(b) Execution will fail because a has the wrong size.
(c) i will have the value 99 at the end of any execution of the segment.
(d) i will have the value of the last element of the array a at the end of any
execution of the segment.
Correct answer is (c)
Your score on this question is: 7.14
Feedback:
See section 1.3.5 of the course notes.
-------------------------------------------------------------------------------11.
We want the variable factorialfunc to hold the address of the first instruction
of the following function:
int factorial(int n) {
if (n == 1) return n;
return n * factorial(n -1);
}
How would we declare the variable?
(a) factorial() * factorialfunc;
(b) we can't: C cannot extract the addresses of instructions.

(c) int (*factorialfunc)(int);


(d) int (int) * factorialfunc
Correct answer is (c)
Your score on this question is: 7.14
Feedback:
See section 1.5.2 of the course notes.
-------------------------------------------------------------------------------12.
Which of the following computations may be performed by exactly one CPU instruc
tion?
a = 5;
a = b + c * 5;
for (i = 0; i < 10; i += a[i++]);

(a) II only
(b) I, II, and III
(c) I only
(d) I and II only
Correct answer is (c)
Your score on this question is: 7.14
Feedback:
See section 1.5.1 of the course notes.
-------------------------------------------------------------------------------13.
Suppose that, using a tool such as the memory window of Visual C++, we found th
at a certain set of contiguous memory locations contained the integer 0xC605CD62
3A8365000000. What could these memory locations hold?
the integer 0xC605CD623A8365000000
a string
a CPU instruction

(a) III only


(b) I and II only
(c) I, II, and III
(d) I only
Correct answer is (c)
Your score on this question is: 7.14
Feedback:
See section 1.5.1 of the course notes.

-------------------------------------------------------------------------------14.
Which of the following
chine code generated by
The resulting code will
The resulting code will
The resulting code will

are true of the effect that optimizations have on the ma


compilers?
be faster and/or smaller.
be clearer.
be harder to debug.

(a) I and II only


(b) I and III only
(c) I only
(d) I, II, and III
Correct answer is (b)

1.
In C, assuming that an int takes 4 bytes, how many bytes are required to repres
ent the following array?
int a[12];
(a) 12
(b) 48
(c) 52
(d) 44
Correct answer is (b)
Your score on this question is: 14.29
Feedback:
See section 2.4.1 of the course notes.

-------------------------------------------------------------------------------2.
How many bytes are allocated by the following C declaration and initialization?
char s[] = "quiz";
(a) 5
(b) 4
(c) 20
(d) 16
Correct answer is (a)

-------------------------------------------------------------------------------3.
Assume that array a is at location 1000 (decimal). Execution of the following p
rogram results in what being printed?
int a[12];
main() {
int i;
for (i = 0; i < 12; i++) a[i] = i;
printf("%d\n", *(a + 5));
}

(a) 5
(b) 1005
(c) 20
(d) 1020
Correct answer is (a)

-------------------------------------------------------------------------------4.
In modern computers, each address represents one _____ of memory.
(a) bit
(b) page
(c) byte
(d) word
Correct answer is (c)

-------------------------------------------------------------------------------5.
What is the purpose of the exponent in floating point numbers?
(a) to indicate where the decimal or binary point should be
(b) the mantissa is raised to the power of the exponent
(c) to specify the base as binary, octal, or hexadecimal
(d) to specify the superscript
Correct answer is (a)

6.
What is the value of the following C expression?
0x1234 ^ 0x5432

(a) 0x5434
(b) 0x1030
(c) 0x5636
(d) 0x4606
Correct answer is (d)
7.
In C, what is the following binary number in hexadecimal?
11010101
(a) 0x5D
(b) 0xAB
(c) 0xB5
(d) 0xD5
Correct answer is (d)

1.
In C, assuming that an int takes 4 bytes, how many bytes are required to repres
ent the following array?
int a[12];
(a) 44
(b) 52
(c) 48
(d) 12
Correct answer is (c)

-------------------------------------------------------------------------------2.
How many bytes are allocated by the following C declaration and initialization?
char s[] = "quiz";
(a) 16
(b) 5
(c) 20
(d) 4
Correct answer is (b)
Your score on this question is: 14.29

Feedback:
See section 2.4.1 of the course notes.
-------------------------------------------------------------------------------3.
Which of
Alignment
Alignment
Alignment

the following statements about alignment within C struct's is true?


may cause the allocation of unused space.
is required by all modern processors.
can help processors access data more efficiently.

(a) I and III only


(b) II and III only
(c) I, II, and III
(d) I only
Correct answer is (a)
Your score on this question is: 0.00
Feedback:
See section 2.4.3 of the course notes.
-------------------------------------------------------------------------------4.
In modern computers, each address represents one _____ of memory.
(a) word
(b) byte
(c) bit
(d) page
Correct answer is (b)
Your score on this question is: 14.29
Feedback:
See section 2.2.1 of the course notes.
-------------------------------------------------------------------------------5.
Why is the mantissa of a floating point number shifted left as far as possible?

(a) to avoid overflow


(b) to avoid underflow
(c) to align bit positions, simplifying addition
(d) to retain as much precision as possible
Correct answer is (d)

Your score on this question is: 14.29


Feedback:
See section 2.3.1 of the course notes.
-------------------------------------------------------------------------------6.
In C, what is the following binary number in hexadecimal?
11010101
(a) 0xAB
(b) 0x5D
(c) 0xB5
(d) 0xD5
Correct answer is (d)
Your score on this question is: 14.29
Feedback:
See section 2.1.2 of the course notes.
-------------------------------------------------------------------------------7.
What is the value of the following C expression?
0x1234 >> 5
(a) 0x0092
(b) 0x0000
(c) 0x0091
(d) 0x00A3
Correct answer is (c)

1.
Which of
Alignment
Alignment
Alignment

the following statements about alignment within C struct's is true?


may cause the allocation of unused space.
is required by all modern processors.
can help processors access data more efficiently.

(a) I only
(b) I and III only
(c) II and III only
(d) I, II, and III
Correct answer is (b)

-------------------------------------------------------------------------------2.
Assume that array a is at location 1000 (decimal). Execution of the following p
rogram results in what being printed?
int a[12];
main() {
int i;
for (i = 0; i < 12; i++) a[i] = i;
printf("%d\n", *(a + 5));
}

(a) 1005
(b) 5
(c) 1020
(d) 20
Correct answer is (b)

-------------------------------------------------------------------------------3.
Given the following declarations, h[] takes 7 bytes and t[] takes 6 bytes. What
is the minimum amount of memory (in bytes) required to store the concatenation
of h and t?
char h[] = "hello ";
char t[] = "there";

(a) 12
(b) 14
(c) 11
(d) 13
Correct answer is (a)

-------------------------------------------------------------------------------4.
In a computer with 4-byte words, which of the following C expressions tests whe
ther ptr contains the address of a word?
(ptr & 3) == 0
(ptr | 3) == 0
(ptr % 4) == 0

(a) III only


(b) I only
(c) I and III only
(d) II only
Correct answer is (c)

-------------------------------------------------------------------------------5.
In C, using default floating point settings, what happens when a floating-point
computation results in an overflow?
(a) A special value "infinity" is computed, testable with _finite().
(b) An exception is raised unless disabled by calling _controlfp().
(c) An erroneous value is computed and execution continues.
(d) Program execution is halted.
Correct answer is (a)

-------------------------------------------------------------------------------6.
What is the value of the following C expression?
0x1234 << 3
(a) 0x1234000
(b) 0x9340
(c) 0x91A0
(d) 0x48CE
Correct answer is (c)

-------------------------------------------------------------------------------7.
What is the value of the following C expression?
0x1234 ^ 0x5432
(a) 0x5434
(b) 0x1030
(c) 0x4606
(d) 0x5636
Correct answer is (c)

1.
Which of the following are true about statically allocated data in C programs?
Its location is chosen by the compiler.
Its location may change during execution if more memory is required.
Its location is not known directly but can be found in a static symbol table.

(a) II and III only.


(b) I only.
(c) III only.
(d) I and II only.
Correct answer is (b)

-------------------------------------------------------------------------------2.
The key feature of implicit memory management is that memory is freed automatic
ally. Which of the following features of C make(s) it difficult to add support f
or implicit memory management in C?
Pointers are not always initialized.
Type casting makes it impossible to know when a value could be a pointer.
C programs can allocate memory at runtime.

(a) I and II only


(b) III only
(c) II only
(d) I only
Correct answer is (a)

-------------------------------------------------------------------------------3.
Why is it wrong to return the address of a local variable?
(a) The variable address is invalid after the return.
(b) It allows illegal access to the variable from arbitrary functions.
(c) The local variable may be in a machine register.
(d) It is faster to return the value of the variable.
Correct answer is (a)
Your score on this question is: 16.67
Feedback:

See section 3.3.3 of the course notes.


-------------------------------------------------------------------------------4.
A memory leak is caused by a
(a) failure to free allocated memory
(b) bug in which too much memory is allocated, causing internal fragmentation
(c) function that allocates a large amount of memory from the heap
(d) bug in the memory allocator that fails to free memory
Correct answer is (a)
Your score on this question is: 16.67
Feedback:
See section 3.3.5 of the course notes.
-------------------------------------------------------------------------------5.
A garbage collector
(a) frees memory blocks that cannot be reached by dereferencing pointers.
(b) frees all memory blocks that will not be accessed in the future.
(c) removes old versions of local variables from the stack .
(d) frees memory blocks marked as "deleteable".
Correct answer is (a)
Your score on this question is: 16.67
Feedback:
See section 3.3.7 of the course notes.
-------------------------------------------------------------------------------6.
In this sequence of C statements
long a[10];
ptr = a + 5;
*ptr++ = x;
the last line could be rewritten as
(a) ptr = ptr + 1; *ptr = x;
(b) a[6] = x;
(c) a[5] = x; ptr = ptr + 1;
(d) ptr = x; *ptr++;
Correct answer is (c)
Your score on this question is: 16.67

Feedback:
See section 3.3.1 of the course notes.
-------------------------------------------------------------------------------Go to top of assessment.
Total score: 83.33
? Copyright 2005 iCarnegie, Inc. All rights reserved.
View Assessment Result

Family Name: Li
Given Name: Qin
Login: nwpu053816
E-mail: lqw3816@163.com
Status: Enrolled
Assessment Name: Multiple-Choice Quiz 3
Instance: 2
Section: NWPU-SSD6-6
During: Fall/Autumn 2007
Section Status: Active
For course: System-Level Programming
(SSD6)
Corresponding to: SSD6
At: Software College of Northwestern Polytechnical University
-------------------------------------------------------------------------------Your performance was as follows:
You took 14 minutes on this assessment from Thu Nov 29 10:04:39 UTC+0800 2007 t
o Thu Nov 29 10:17:45 UTC+0800 2007.
Total score: 50.00

1.
Suppose a compiler uses static storage to store all variables, function paramet
ers, saved registers, and return addresses. Which of the following language feat
ures can this compiler support?
Local variables.
Function calls.
Recursion.

(a) I, II, and III


(b) I and II only
(c) II only
(d) I only
Correct answer is (b)
Your score on this question is: 0.00
Feedback:
See section 3.1.2 of the course notes.

-------------------------------------------------------------------------------2.
Which of the following are true about statically allocated data in C programs?
Its location is chosen by the compiler.
Its location may change during execution if more memory is required.
Its location is not known directly but can be found in a static symbol table.

(a) III only.


(b) I only.
(c) I and II only.
(d) II and III only.
Correct answer is (b)
Your score on this question is: 16.67
Feedback:
See section 3.1.1 of the course notes.
-------------------------------------------------------------------------------3.
Why is it wrong to return the address of a local variable?
(a) The local variable may be in a machine register.
(b) It is faster to return the value of the variable.
(c) The variable address is invalid after the return.
(d) It allows illegal access to the variable from arbitrary functions.
Correct answer is (c)
Your score on this question is: 16.67
Feedback:
See section 3.3.3 of the course notes.
--------------------------------------------------------------------------------

4.
In C, to allocate an array of 100 longs on the heap you should write
(a) long *a = (long *) malloc(100);
(b) long a[] = (long *) malloc(100);
(c) long a[100] = (long *) malloc(sizeof(a));
(d) long *a = (long *) malloc(100 * sizeof(long));
Correct answer is (d)
Your score on this question is: 16.67
Feedback:
See section 3.3.3 of the course notes.
-------------------------------------------------------------------------------5.
In C, when a struct is freed,
(a) only those pointers within the struct that point into the heap are freed a
utomatically.
(b) any pointers within the struct are also freed automatically.
(c) a destructor function is called automatically to clean up.
(d) no pointers within the struct are freed automatically.
Correct answer is (d)
Your score on this question is: 0.00
Feedback:
See section 3.3.5 of the course notes.
-------------------------------------------------------------------------------6.
In C, which of the following is the best way to detect when a pointer is freed
twice?
(a) Modify free() to set the freed data to zero.
(b) Set pointers to NULL after freeing them.
(c) Keep a log of addresses that have been freed and scan the log before callin
g free().
(d) Flag all blocks as free or not, and check the flag when calling free().
Correct answer is (d)
Your score on this question is: 0.00
Feedback:
See section 3.3.6 of the course notes.
--------------------------------------------------------------------------------

Go to top of assessment.
Total score: 50.00
? Copyright 2005 iCarnegie, Inc. All rights reserved.
View Assessment Result: Multiple-Choice Quiz 1

Your performance was as follows:


1.
Which of the following does a debugger do?
Analyze the source code to find programming errors.
Decode machine code generated by a compiler.
Stop execution of a program.

(a) I and III only


(b) II and III only
(c) III only
(d) I, II, and III.
Correct answer is (b)
Your score on this question is: 0.00
Feedback:
See section 1.1.3 of the course notes.
-------------------------------------------------------------------------------2.
Consider the following fragment of C++ source code.
String msg; unsigned int x; int y;
cin >> msg >> x >> y;
cout << x + y;
Which of the following is (are) true regarding execution of the segment?
The input statement will always take the same amount of time to execute.
The output statement will always be executed immediately after the input stateme
nt.
If x and y are both positive, an integer greater than both will be printed.

(a) I and II only


(b) none
(c) II and III only
(d) II only
Correct answer is (b)
Your score on this question is: 7.14

Feedback:
See section 1.1.1 of the course notes.
-------------------------------------------------------------------------------3.
When using a debugger to find the cause of a program's incorrect behavior,
(a) the program is usually executed to the point at which the behavior occurs
and then executed backwards to find the cause
(b) the faulty code fragment must first be identified
(c) it is fastest to start by stopping the debugger long before the behavior ap
pears
(d) it is often necessary to start the program multiple times under the debugge
r
Correct answer is (d)
Your score on this question is: 0.00
Feedback:
See section 1.2.4 of the course notes.
-------------------------------------------------------------------------------4.
When debugging using Visual C++, which of the following are possible through th
e Watch window?
The program's execution can be stopped.
The value of an arbitrary C expression can be calculated.
The value of a program variable can be set.

(a) II only
(b) III only
(c) I, II, and III.
(d) II and III only
Correct answer is (d)
Your score on this question is: 0.00
Feedback:
See section 1.2.3 of the course notes.
-------------------------------------------------------------------------------5.
Activation records are organized in stacks because
(a) they are seldom needed during program execution.
(b) stacks are simple enough for the hardware to manage.
(c) stacks allow activation records to be pushed and popped in any order.
(d) functions need to access all the variables of the functions that call them.

Correct answer is (b)


Your score on this question is: 0.00
Feedback:
See section 1.4.2 of the course notes.
-------------------------------------------------------------------------------6.
Consider the following program.
int square(int * arg) {
int n = * arg;
return n * n;
}
int main (int argc, char * argv[]) {
int arg = strtol(argv[1], NULL, 0);
return square(arg);
}
When it is executed with the argument 5, the variable n is allocated to
(a) many addresses chosen by the compiler.
(b) exactly one address chosen by the compiler.
(c) exactly one address not known to the compiler.
(d) many addresses neither of which are known to the compiler.
Correct answer is (c)
Your score on this question is: 0.00
Feedback:
See section 1.4.1 of the course notes.
-------------------------------------------------------------------------------7.
Consider the following program.
int i;
int j = 1;
int callee(int number) {
int plusone;
plusone = number + 1;
return plusone;
}
int main (int argc, char *argv[]) {
if (j == 1) return callee(i);
return j;
}
Which of the following are allocated in the activation record immediately after
the function callee() is invoked?
(a) plusone only.

(b) i, j and number only.


(c) i only.
(d) plusone and number only.
Correct answer is (d)
Your score on this question is: 0.00
Feedback:
See section 1.4.2 of the course notes.
-------------------------------------------------------------------------------8.
What does the following program print?
int callee(int * count) {
count++;
return *count;
}
int main (int argc, char *argv[]) {
int count = 4;
int retval;
retval = callee(&count);
printf("%d", retval);
return 0;
}

(a) 8
(b) 5
(c) cannot be determined from the information given.
(d) 4
Correct answer is (c)
Your score on this question is: 7.14
Feedback:
See section 1.4.1 of the course notes.
-------------------------------------------------------------------------------9.
In a computer in which both addresses and integers are 32 bits wide, how many b
ytes of memory will the compiler allocate as a result of the following pointer d
eclaration?
int * pointer;
(a) 4
(b) 8
(c) 0
(d) 64
Correct answer is (a)

Your score on this question is: 7.14


Feedback:
See section 1.3.2 of the course notes.
-------------------------------------------------------------------------------10.
Consider the following code fragment.
int a;
int b;
int main(int argc, char *argv[]) {
int c;
int d;
...
/* some code */
}
Which of the following must be true?
(a) The value of *d is closer to the value of *c than to the value of *a.
(b) The values of *a and *b are closer to each other than the values of *c and
*d.
(c) The value of &d is closer to the value of &c than to the value of &a.
(d) The values of &a and &b are closer to each other than the values of &c and
&d.
Correct answer is (c)
Your score on this question is: 7.14
Feedback:
See section 1.3.1 of the course notes.
-------------------------------------------------------------------------------11.
Which of the following is a good reason (are good reasons) to equip the CPU wit
h small amounts of fast memory?
To make the design of the compiler simpler
To make some CPU instructions smaller
To make some CPU instructions faster

(a) III only


(b) I, II, and III
(c) II only
(d) II and III only
Correct answer is (d)
Your score on this question is: 0.00
Feedback:
See section 1.5.3 of the course notes.

-------------------------------------------------------------------------------12.
Programs compiled for an Intel Pentium processor do not execute properly on a S
PARC processor from Sun Microsystems because
(a) the assembly mnemonics for the same "opcode" are different in the two proc
essors
(b) copyrights regarding code cannot be violated
(c) the operation codes understood by the two processors are different
(d) the memory of a SPARC CPU is numbered from top to bottom
Correct answer is (c)
Your score on this question is: 0.00
Feedback:
See section 1.5.1 of the course notes.
(a) The assembly mnemonics can be different and yet assemble into the same op
codes
-------------------------------------------------------------------------------13.
Immediately after the CPU executes an instruction that is neither a branch nor
a jump instruction, the program counter
(a) has a value that cannot be determined without further information
(b) is incremented to point to the following instruction
(c) remains unchanged
(d) is incremented by one
Correct answer is (b)
Your score on this question is: 0.00
Feedback:
See section 1.5.2 of the course notes.
-------------------------------------------------------------------------------14.
A branch instruction
(a) sets the program counter to one of two possible values
(b) sets the program counter to one of many possible values
(c) increases the program counter by a fixed amount
(d) unconditionally sets the program counter to its operand
Correct answer is (a)
Your score on this question is: 0.00
Feedback:

See section 1.5.2 of the course notes.


-------------------------------------------------------------------------------Go to top of assessment.
Total score: 28.57
? Copyright 2005 iCarnegie, Inc. All rights reserved.
View Assessment Result: Multiple-Choice Quiz 1

Your performance was as follows:


1.
Compared to a sequence of machine code instructions, a fragment of C code
(a) may describe the same algorithm
(b) describes the actions of the computer, not just of the CPU
(c) is the native way to program most computers
(d) does not engage any transistors during its execution
Correct answer is (a)
Your score on this question is: 7.14
Feedback:
See section 1.1.2 of the course notes.
-------------------------------------------------------------------------------2.
Which of the following does a debugger do?
Analyze the source code to find programming errors.
Decode machine code generated by a compiler.
Stop execution of a program.

(a) I and III only


(b) III only
(c) I, II, and III.
(d) II and III only
Correct answer is (d)
Your score on this question is: 7.14
Feedback:
See section 1.1.3 of the course notes.
-------------------------------------------------------------------------------3.

In Visual C++, a Win32 Console Application is


(a) the simplest type of application Visual C++ can generate
(b) the status window of the Visual C++ environment
(c) built by using sophisticated "Application Wizards"
(d) a program that is able to control the operating system of a windows compute
r
Correct answer is (a)
Your score on this question is: 0.00
Feedback:
See section 1.2.1 of the course notes.
-------------------------------------------------------------------------------4.
When debugging using Visual C++, which of the following are possible through th
e Watch window?
The program's execution can be stopped.
The value of an arbitrary C expression can be calculated.
The value of a program variable can be set.

(a) II only
(b) III only
(c) I, II, and III.
(d) II and III only
Correct answer is (d)
Your score on this question is: 7.14
Feedback:
See section 1.2.3 of the course notes.
-------------------------------------------------------------------------------5.
Consider the function factorial() defined as follows.
int factorial(int n) {
if (n == 1) return n;
return n * factorial(n - 1);
}
How many activation records of factorial are allocated by invocation of the expr
ession factorial(4)?
(a) 5
(b) 4
(c) 0
(d) 1
Correct answer is (b)

Your score on this question is: 7.14


Feedback:
See section 1.4.2 of the course notes.
-------------------------------------------------------------------------------6.
When executing a function callee(), which of the following are true regarding t
he value of the frame pointer?
It marks the top of the stack frame of the function that invoked callee().
It marks the bottom of the stack frame of callee()
It is the top of the stack.

(a) I and II only


(b) III only
(c) II only
(d) I only
Correct answer is (a)
Your score on this question is: 7.14
Feedback:
See section 1.4.2 of the course notes.
-------------------------------------------------------------------------------7.
At which of the following times is an activation record created?
When a program starts executing.
Every time a function is invoked.
When a variable is declared.

(a) III only


(b) I and II only
(c) II and III only
(d) II only
Correct answer is (b)
Your score on this question is: 7.14
Feedback:
See section 1.4.2 of the course notes.
(b) The program starts executing by calling the function main().
-------------------------------------------------------------------------------8.
What does the following program print?
void callee(int * count) {

count++;
}
int main (int argc, char *argv[]) {
int count = 4;
callee(&count);
printf("%d", count);
return 0;
}

(a) 5
(b) 8
(c) cannot be determined from the information given.
(d) 4
Correct answer is (d)
Your score on this question is: 0.00
Feedback:
See section 1.4.1 of the course notes.
-------------------------------------------------------------------------------9.
Consider the following segment of a C program.
int i = 99;
int a[100];
i = a[i + 1];
Which of the following is true of the segment?
(a) When executed, the program will be prematurely terminated by the operating
system because of an illegal memory access.
(b) i will have the value of the last element of the array a at the end of any
execution of the segment.
(c) i will have the value 99 at the end of any execution of the segment.
(d) Execution will fail because a has the wrong size.
Correct answer is (c)
Your score on this question is: 7.14
Feedback:
See section 1.3.5 of the course notes.
-------------------------------------------------------------------------------10.
In one computer, the bytes with addresses A, A+1, A+2 and A+3 contain the integ
er 256, and the variable declared with int * a; has the value A. In a different
computer, the bytes with addresses B, B+1, B+2 and B+3 also contain the integer
256, and the variable declared with int * b has the value B. Which of the follow
ing are necessarily true?
The contents of A+1 are equal to the contents of B+1.

The contents of A+1 are equal to the contents of B+2.


*a == *b

(a) II and III only


(b) I and III only
(c) I only
(d) III only
Correct answer is (d)
Your score on this question is: 0.00
Feedback:
See section 1.3.3 of the course notes.
-------------------------------------------------------------------------------11.
Programs compiled for an Intel Pentium processor do not execute properly on a S
PARC processor from Sun Microsystems because
(a) copyrights regarding code cannot be violated
(b) the assembly mnemonics for the same "opcode" are different in the two proce
ssors
(c) the memory of a SPARC CPU is numbered from top to bottom
(d) the operation codes understood by the two processors are different
Correct answer is (d)
Your score on this question is: 7.14
Feedback:
See section 1.5.1 of the course notes.
-------------------------------------------------------------------------------12.
The program counter contains
(a) the address of the CPU instruction that is about to be executed
(b) the number of CPU instructions a program has executed so far
(c) the amount of memory a program is currently using
(d) the number of times a program has been executed
Correct answer is (a)
Your score on this question is: 0.00
Feedback:
See section 1.5.2 of the course notes.
--------------------------------------------------------------------------------

13.
Which of the following computations may be performed by exactly one CPU instruc
tion?
a = 5;
a = b + c * 5;
for (i = 0; i < 10; i += a[i++]);

(a) II only
(b) I only
(c) I, II, and III
(d) I and II only
Correct answer is (b)
Your score on this question is: 7.14
Feedback:
See section 1.5.1 of the course notes.
-------------------------------------------------------------------------------14.
Immediately after the CPU executes an instruction that is neither a branch nor
a jump instruction, the program counter
(a) is incremented to point to the following instruction
(b) has a value that cannot be determined without further information
(c) remains unchanged
(d) is incremented by one
Correct answer is (a)
Your score on this question is: 7.14
Feedback:
See section 1.5.2 of the course notes.
-------------------------------------------------------------------------------Go to top of assessment.
Total score: 71.43
? Copyright 2005 iCarnegie, Inc. All rights reserved.
View Assessment Result: Multiple-Choice Quiz 1

Your performance was as follows:


1.
Integrated programming environments make it difficult to mix and match tools fr
om different sources. This is

(a) good, because tools from different sources cannot be made to interact with
each other
(b) bad, because no single vendor is likely to be the source of all the best to
ols
(c) bad, because all the tools will then have the same user interface
(d) good, because it ensures compilation is not done incrementally by accident
Correct answer is (b)
Your score on this question is: 0.00
Feedback:
See section 1.1.4 of the course notes.
-------------------------------------------------------------------------------2.
Compared to a sequence of machine code instructions, a fragment of C code
(a) describes the actions of the computer, not just of the CPU
(b) may describe the same algorithm
(c) does not engage any transistors during its execution
(d) is the native way to program most computers
Correct answer is (b)
Your score on this question is: 7.14
Feedback:
See section 1.1.2 of the course notes.
-------------------------------------------------------------------------------3.
Within Visual C++, which of the following will reveal the value of a variable w
hen the program is stopped at a breakpoint?
Placing the mouse pointer over the variable name in the source file window.
Inserting a printf() in the program.
Typing the variable name on the "Watch" window.

(a) III only


(b) I and III only
(c) I, II, and III
(d) II and III only
Correct answer is (b)
Your score on this question is: 7.14
Feedback:
See section 1.2.3 of the course notes.

-------------------------------------------------------------------------------4.
In Visual C++, a Win32 Console Application is
(a) the status window of the Visual C++ environment
(b) the simplest type of application Visual C++ can generate
(c) a program that is able to control the operating system of a windows compute
r
(d) built by using sophisticated "Application Wizards"
Correct answer is (b)
Your score on this question is: 7.14
Feedback:
See section 1.2.1 of the course notes.
-------------------------------------------------------------------------------5.
What does the following program print?
void callee(int * count) {
count++;
}
int main (int argc, char *argv[]) {
int count = 4;
callee(&count);
printf("%d", count);
return 0;
}

(a) 4
(b) 5
(c) cannot be determined from the information given.
(d) 8
Correct answer is (a)
Your score on this question is: 0.00
Feedback:
See section 1.4.1 of the course notes.
-------------------------------------------------------------------------------6.
Consider the function factorial() defined as follows.
int factorial(int n) {
if (n == 1) return n;
return n * factorial(n - 1);
}
How many activation records of factorial are allocated by invocation of the expr

ession factorial(4)?
(a) 0
(b) 4
(c) 5
(d) 1
Correct answer is (b)
Your score on this question is: 7.14
Feedback:
See section 1.4.2 of the course notes.
-------------------------------------------------------------------------------7.
Activation records are organized in stacks because
(a) functions need to access all the variables of the functions that call them
.
(b) they are seldom needed during program execution.
(c) stacks allow activation records to be pushed and popped in any order.
(d) stacks are simple enough for the hardware to manage.
Correct answer is (d)
Your score on this question is: 7.14
Feedback:
See section 1.4.2 of the course notes.
-------------------------------------------------------------------------------8.
Consider the following program.
int i;
int j = 1;
int callee(int number) {
int plusone;
plusone = number + 1;
return plusone;
}
int main (int argc, char *argv[]) {
if (j == 1) return callee(i);
return j;
}
Which of the following are allocated in the activation record immediately after
the function callee() is invoked?
(a) plusone and number only.
(b) plusone only.
(c) i, j and number only.
(d) i only.

Correct answer is (a)


Your score on this question is: 7.14
Feedback:
See section 1.4.2 of the course notes.
-------------------------------------------------------------------------------9.
In a computer in which both addresses and integers are 32 bits wide, how many b
ytes of memory will the compiler allocate for following code fragment?
int a;
int * b = &a;

(a) 8
(b) 32
(c) 4
(d) 0
Correct answer is (a)
Your score on this question is: 0.00
Feedback:
See section 1.3.2 of the course notes.
-------------------------------------------------------------------------------10.
The Visual C++ Memory window displays
(a) the names and values of variables in memory, interpreted in one of several
ways
(b) the names and values of variables in memory, interpreted as 32-bit integers
no matter what the variables' types
(c) the contents of memory, interpreted as 32-bit integers, without the associa
ted variable names
(d) the contents of memory, interpreted in one of several ways, without the ass
ociated variable names
Correct answer is (d)
Your score on this question is: 0.00
Feedback:
See section 1.3.3 of the course notes.
-------------------------------------------------------------------------------11.
Immediately after the CPU executes an instruction that is neither a branch nor

a jump instruction, the program counter


(a) remains unchanged
(b) has a value that cannot be determined without further information
(c) is incremented by one
(d) is incremented to point to the following instruction
Correct answer is (d)
Your score on this question is: 7.14
Feedback:
See section 1.5.2 of the course notes.
-------------------------------------------------------------------------------12.
A CPU register is a word of CPU memory that
(a) is explicitly loaded and unloaded from normal memory by compiler-generated
instructions
(b) records the results of periodic CPU diagnostics
(c) houses a critical variable for the duration of the execution of a program
(d) is automatically loaded when a CPU instruction refers to a word of normal m
emory
Correct answer is (a)
Your score on this question is: 7.14
Feedback:
See section 1.5.3 of the course notes.
-------------------------------------------------------------------------------13.
Which of the following
chine code generated by
The resulting code will
The resulting code will
The resulting code will

are true of the effect that optimizations have on the ma


compilers?
be faster and/or smaller.
be clearer.
be harder to debug.

(a) I and II only


(b) I only
(c) I, II, and III
(d) I and III only
Correct answer is (d)
Your score on this question is: 7.14
Feedback:
See section 1.5.3 of the course notes.

-------------------------------------------------------------------------------14.
Suppose that, using a tool such as the memory window of Visual C++, we found th
at a certain set of contiguous memory locations contained the integer 0xC605CD62
3A8365000000. What could these memory locations hold?
the integer 0xC605CD623A8365000000
a string
a CPU instruction

(a) I only
(b) I, II, and III
(c) III only
(d) I and II only
Correct answer is (b)
Your score on this question is: 7.14
Feedback:
See section 1.5.1 of the course notes.
-------------------------------------------------------------------------------Go to top of assessment.
Total score: 71.43
? Copyright 2005 iCarnegie, Inc. All rights reserved.
1.

For an STL iterator it, execution of the statement


++it;
does which of the following?
(a) Advances the iterator to the next item.
(b) Post-increments the item to which the iterator points.
(c) Increase by 1 the size of the container pointed to by it.
(d) Pre-increments the item to which the iterator points.
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 2.1.3 of the course notes.
2.
Which of the following data structures is not a container implemented in the C++
Standard Template Library?
(a) Stack

(b) List
(c) Vector
(d) Hash table
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 2.1.1, subsection "STL Overview," in the course notes.
3.
In the STL, common algorithms are instantiated for multiple types of container c
lasses by using _____ to provide a uniform interface between the algorithms and
containers.
(a) pointers
(b) virtual functions
(c) arrays
(d) iterators
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 2.1.1, subsection "Iterators," in the course notes.
4.
In the C++ Standard Template Library, vectors and deques differ in their interfa
ces for handling which of the following operations?
1. Insertion of an element at the front of the container
2. Insertion of an element at the end of the container
3. Removal of an element from the front of the container

(a) III only


(b) I only
(c) I and III only
(d) I and II only
Correct answer is

(c)

Your score on this question is:


Feedback:

10.00

See Section 2.2.3, subsection "Interface," in the course notes.


5.
Consider the following program fragment that calls the method count_if in the C+
+ Standard Template Library.
deque<int> numbers;
...
count_if(numbers.begin(), numbers.end(), is_odd);
Which of the following declarations for the method is_odd is correct for the cal
l to count_if?
(a) bool is_odd(int begin, int end);
(b) int is_odd(bool i);
(c) bool is_odd(int i);
(d) int is_odd(int begin, int end);
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See Section 2.2.3, subsection "Interface," in the course notes.
6.
Consider the following program segment.
vector<int> A(10);
A.resize(0);
A.push_back(5000);
At the end of an execution of this fragment, the size of vector A is
(a) 0
(b) 1
(c) 5000
(d) 10
Correct answer is

(b)

Your score on this question is:


Feedback:
See section 2.1.2 of the course notes.
7.

10.00

Consider the execution of the following.


vector<int> A(10,20);
Which of the following accurately describes what is created?
(a) An array of 20 arrays of ints, each of size 10
(b) An array of 10 arrays of ints, each of size 20
(c) An array of 10 ints, each initialized to 20
(d) An array of ints, indexed from 10 to 20
Correct answer is

(c)

Your score on this question is:

0.00

Feedback:
See section 2.1.2 of the course notes.
8.
The size of an STL vector is defined to be the
(a) total of the sizes of the data
(b) maximum number of elements that can be
(c) number of bytes the vector occupies in
(d) number of elements currently stored in
Correct answer is

members in the vector class


stored in the vector without resizing
memory
the vector

(d)

Your score on this question is:

10.00

Feedback:
See section 2.1.2 of the course notes.
9.
Which of the following statements is (are) true regarding C-style strings?
1. They are terminated by the null character.
2. Storing a five-character string requires at least seven characters.

(a) I only
(b) I and II
(c) None
(d) II only
Correct answer is

(a)

Your score on this question is:

0.00

Feedback:
See section 2.1, subsection "C-style Strings," in the course notes.
10.

Consider the following C++ program fragment, which is a partial declaration of t


he class string.
class string {
public:
string(const char* cstring = "");
bool operator== (const string & rhs);
...
};
Given this class and two string objects called s1 and s2, which of the following
is not a legal statement?
(a) string s3("Hello, World");
(b) bool ans = (s2 == "hello");
(c) bool ans = (s1 == s2);
(d) bool ans = ("hello" == s1);
Correct answer is

(d)

Your score on this question is:

0.00

Feedback:
See Chapter 2, pages 76C77, in the course textbook.
1.
Which of the following data structures is not a container implemented in the C++
Standard Template Library?
(a) Hash table
(b) Stack
(c) List
(d) Vector
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 2.1.1, subsection "STL Overview," in the course notes.
2.
In the STL, common algorithms are instantiated for multiple types of container c
lasses by using _____ to provide a uniform interface between the algorithms and
containers.
(a) virtual functions

(b) arrays
(c) pointers
(d) iterators
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 2.1.1, subsection "Iterators," in the course notes.
3.
For an STL iterator it, execution of the statement
it--;
does which of the following?
(a) Pre-decrements the item to which the iterator points.
(b) Decreases by 1 the size of the container pointed to by it.
(c) Steps the iterator backwards to the previous item.
(d) Post-decrements the item to which the iterator points.
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 2.1.3 of the course notes.
4.
In the C++ Standard Template Library, vectors and deques differ in their interfa
ces for handling which of the following operations?
1. Insertion of an element at the front of the container
2. Insertion of an element at the end of the container
3. Removal of an element from the front of the container

(a) I and III only


(b) III only
(c) I and II only
(d) I only
Correct answer is

(a)

Your score on this question is:


Feedback:

10.00

See Section 2.2.3, subsection "Interface," in the course notes.


5.
The STL deque container contains which of the following methods?
1. push_back
2. push_front
3. pop_front

(a) II and III only


(b) I, II, and III
(c) I only
(d) III only
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 2.2.3, subsection "Interface," in the course notes.
6.
In STL vectors, _____ refers to the maximum number of items that can be stored w
ithout resizing, and _____ refers to the number of items stored.
(a) range, domain
(b) domain, range
(c) size, capacity
(d) capacity, size
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 2.1.2 of the course notes.
7.
Consider the following declaration that makes use of a user-defined class Thing.
vector<Thing> A(10);
In order that it compile, the class Thing must have which of the following?
(a) a copy constructor
(b) an assignment operator

(c) a default constructor


(d) a destructor
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 2.1.2 of the course notes.
8.
Consider the following program segment.
vector<int> A(10);
A.resize(0);
A.push_back(5000);
At the end of an execution of this fragment, the size of vector A is
(a) 1
(b) 10
(c) 0
(d) 5000
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 2.1.2 of the course notes.
9.
Which of the following statements is (are) true regarding C-style strings?
1. They are terminated by the null character.
2. Storing a five-character string requires at least seven characters.

(a) I only
(b) II only
(c) None
(d) I and II
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 2.1, subsection "C-style Strings," in the course notes.
10.

A C-style string is stored as an array of characters that ends with _____ charac
ter.
(a) a '\n'
(b) any white-space
(c) a '0'
(d) a '\0'
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See Chapter 2, page 74, in the course textbook.
1.
Which of the following data structures is not a container implemented in the C++
Standard Template Library?
(a) Hash table
(b) List
(c) Stack
(d) Vector
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 2.1.1, subsection "STL Overview," in the course notes.
2.
The main abstractions of the Standard Template Library include which of the foll
owing?
1. Iterators
2. Exception handlers
3. Algorithms

(a) I and III only


(b) I and II only
(c) III only
(d) I only
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 2.1.1, subsection "STL Overview," in the course notes.
3.
In the STL, common algorithms are instantiated for multiple types of container c
lasses by using _____ to provide a uniform interface between the algorithms and
containers.
(a) arrays
(b) iterators
(c) pointers
(d) virtual functions
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 2.1.1, subsection "Iterators," in the course notes.
4.
The STL deque container contains which of the following methods?
1. push_back
2. push_front
3. pop_front

(a) I, II, and III


(b) II and III only
(c) I only
(d) III only
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 2.2.3, subsection "Interface," in the course notes.
5.

In the C++ Standard Template Library, vectors and deques differ in their interfa
ces for handling which of the following operations?
1. Insertion of an element at the front of the container
2. Insertion of an element at the end of the container
3. Removal of an element from the front of the container

(a) I and II only


(b) I only
(c) III only
(d) I and III only
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See Section 2.2.3, subsection "Interface," in the course notes.
6.
Consider the following declaration that makes use of a user-defined class Thing.
vector<Thing> A(10);
In order that it compile, the class Thing must have which of the following?
(a) a destructor
(b) a copy constructor
(c) a default constructor
(d) an assignment operator
Correct answer is

(c)

Your score on this question is:

0.00

Feedback:
See section 2.1.2 of the course notes.
7.
Consider the execution of the following.
vector<int> A(10,20);
Which of the following accurately describes what is created?
(a) An array of ints, indexed from 10 to 20
(b) An array of 10 arrays of ints, each of size 20
(c) An array of 20 arrays of ints, each of size 10
(d) An array of 10 ints, each initialized to 20

Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 2.1.2 of the course notes.
8.
Consider the following program segment.
vector<int> A(10);
A.resize(0);
A.push_back(5000);
At the end of an execution of this fragment, the size of vector A is
(a) 5000
(b) 10
(c) 1
(d) 0
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 2.1.2 of the course notes.
9.
Which of the following statements is (are) true regarding strings in C++?
1. Strings in C++ are supported by the standard class string.
2. A constructor for the class string can accept a C-style string as an argum
ent.

(a) I only
(b) II only
(c) I and II
(d) None
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 2.1, subsection "C-style Strings," in the course notes.
10.

A C-style string is stored as an array of characters that ends with _____ charac
ter.
(a) any white-space
(b) a '0'
(c) a '\n'
(d) a '\0'
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See Chapter 2, page 74, in the course textbook.
1.
Execution of which of the following statements sets an STL iterator it s
o that it points to the first element of a container A?
(a) begin( A, it );
(b) it = A.begin();
(c) A.reset( it );
(d) A.begin( it );
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 2.1.3 of the course notes.
2.
For an STL iterator it, execution of the statement
++it;
does which of the following?
(a) Pre-increments the item to which the iterator points.
(b) Post-increments the item to which the iterator points.
(c) Increase by 1 the size of the container pointed to by it.
(d) Advances the iterator to the next item.
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 2.1.3 of the course notes.
3.
The main abstractions of the Standard Template Library include which of the foll

owing?
1. Iterators
2. Exception handlers
3. Algorithms

(a) III only


(b) I only
(c) I and II only
(d) I and III only
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 2.1.1, subsection "STL Overview," in the course notes.
4.
The class vector in the C++ STL contains which of the following methods?
1. push_back
2. push_front
3. pop_front

(a) II and III only


(b) I only
(c) I and II only
(d) I, II, and III
Correct answer is

(b)

Your score on this question is:

0.00

Feedback:
See section 2.2.3, subsection "Interface," in the course notes.
5.
Consider the following program fragment that calls the method count_if in the C+
+ Standard Template Library.
deque<int> numbers;
...
count_if(numbers.begin(), numbers.end(), is_odd);
Which of the following declarations for the method is_odd is correct for the cal

l to count_if?
(a) bool is_odd(int i);
(b) int is_odd(bool i);
(c) int is_odd(int begin, int end);
(d) bool is_odd(int begin, int end);
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See Section 2.2.3, subsection "Interface," in the course notes.
6.
In STL vectors, _____ refers to the maximum number of items that can be stored w
ithout resizing, and _____ refers to the number of items stored.
(a) range, domain
(b) domain, range
(c) size, capacity
(d) capacity, size
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 2.1.2 of the course notes.
7.
If A is an STL vector, then the effect of executing the statement
A[i] = x;
is to
(a) check array bounds, enlarge the vector if necessary, and then write
x to position i
(b) write x to position i of the vector, without bounds checking
(c) check array bounds, and write x to position i if and only if i is in the pro
per range
(d) create an iterator x pointing to position i in the array
Correct answer is

(b)

Your score on this question is:


Feedback:
See section 2.1.2 of the course notes.

0.00

8.
The size of an STL vector is defined to be the
(a) total of the sizes of the data
(b) number of elements currently stored in
(c) maximum number of elements that can be
(d) number of bytes the vector occupies in
Correct answer is

members in the vector class


the vector
stored in the vector without resizing
memory

(b)

Your score on this question is:

10.00

Feedback:
See section 2.1.2 of the course notes.
9.
Which of the following statements is (are) true regarding strings in C++?
1. Strings in C++ are supported by the standard class string.
2. A constructor for the class string can accept a C-style string as an argum
ent.

(a) I and II
(b) II only
(c) None
(d) I only
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 2.1, subsection "C-style Strings," in the course notes.
10.
Consider the following C++ program fragment, which is a partial declaration of t
he class string.
class string {
public:
string(const char* cstring = "");
bool operator== (const string & rhs);
...
};
Given this class and two string objects called s1 and s2, which of the following
is not a legal statement?
(a) bool ans = (s2 == "hello");

(b) bool ans = (s1 == s2);


(c) bool ans = ("hello" == s1);
(d) string s3("Hello, World");
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See Chapter 2, pages 76C77, in the course textbook.
1.
The STL is heavily based on
(a) inheritance
(b) templates
(c) object oriented programming
(d) polymorphism
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 2.1.1 of the course notes.
2.
For an STL iterator it, execution of the statement
it--;
does which of the following?
(a) Decreases by 1 the size of the container pointed to by it.
(b) Pre-decrements the item to which the iterator points.
(c) Steps the iterator backwards to the previous item.
(d) Post-decrements the item to which the iterator points.
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 2.1.3 of the course notes.
3.
Access to ranges of elements in an STL container is typically handled by
(a) references
(b) pointers
(c) suitable access member functions
(d) iterators
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 2.1.3 of the course notes.
4.
Consider the following program fragment that calls the method count_if in the C+
+ Standard Template Library.
deque<int> numbers;
...
count_if(numbers.begin(), numbers.end(), is_odd);
Which of the following declarations for the method is_odd is correct for the cal
l to count_if?
(a) int is_odd(bool i);
(b) int is_odd(int begin, int end);
(c) bool is_odd(int begin, int end);
(d) bool is_odd(int i);
Correct answer is

(d)

Your score on this question is:

0.00

Feedback:
See Section 2.2.3, subsection "Interface," in the course notes.
5.
The STL deque container contains which of the following methods?
1. push_back
2. push_front
3. pop_front

(a) II and III only


(b) I only
(c) I, II, and III
(d) III only
Correct answer is

(c)

Your score on this question is:

0.00

Feedback:
See section 2.2.3, subsection "Interface," in the course notes.

6.
The size of an STL vector is defined to be the
(a) maximum number of elements that can be stored in the vector without
resizing
(b) number of elements currently stored in the vector
(c) number of bytes the vector occupies in memory
(d) total of the sizes of the data members in the vector class
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 2.1.2 of the course notes.
7.
In STL vectors, _____ refers to the maximum number of items that can be stored w
ithout resizing, and _____ refers to the number of items stored.
(a) domain, range
(b) capacity, size
(c) size, capacity
(d) range, domain
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 2.1.2 of the course notes.
8.
If A is an STL vector, then the effect of executing the statement
A[i] = x;
is to
(a) check array bounds, and write x to position i if and only if i is in
the proper range
(b) check array bounds, enlarge the vector if necessary, and then write x to pos
ition i
(c) create an iterator x pointing to position i in the array
(d) write x to position i of the vector, without bounds checking
Correct answer is

(d)

Your score on this question is:


Feedback:
See section 2.1.2 of the course notes.
9.

0.00

Which of the following statements is (are) true regarding C-style strings?


1. They are terminated by the null character.
2. Storing a five-character string requires at least seven characters.

(a) II only
(b) I only
(c) I and II
(d) None
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 2.1, subsection "C-style Strings," in the course notes.
10.
Consider the following C++ program segment, assuming that string is a class.
string str1("Hello, World");
str1[5] = 'Z';
The overloaded operator[] function invoked in the above program segment should h
ave which of the following return types?
(a) char &
(b) char
(c) char *
(d) const char &
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See Chapter 2, pages 79C81, in the course textbook.
4.
A typical implementation of a deque in the C++ STL minimizes the need to copy el
ements upon the frontal insertion of new items by
(a) inserting the element at the next available position in the deque an
d maintaining a table of element positions
(b) inserting the element at the end of the deque and maintaining a table of ele
ment positions

(c) using a background thread to reallocate memory when necessary


(d) reserving memory at the front of the deque's stored elements
Correct answer is

(d)

Your score on this question is:

10.00

5.
Which of the following statements is (are) true of typical implementations of ve
ctors and deques?
1.
uses
2.
ns at

A vector's implementation uses one array, whereas a deque's implementation


multiple arrays.
Insertions at the front of a deque tend to be more efficient than insertio
the front of a vector.

(a) II only
(b) I only
(c) None
(d) I and II
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 2.2.3, subsection "Implementation," in the course notes.
1.
Consider the following C++ program segment, which uses the STL.
stack<int,vector<int> > S;
Execution of the statement results in creation of which of the following?
(a) A stack of integers
(b) A vector of integers
(c) A vector of integer stacks
(d) A stack of integer vectors
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 2.4.2 of the course notes.
2.
In the C++ Standard Template Library (STL), the class queue is _____ that uses _
____ for storage.

(a) a sequence container, an adapter class


(b) an adapter, a C-style array
(c) an adapter, a sequence container
(d) a sequence container, a C-style array
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See Chapter 7, page 249, in the course textbook.
3.
In C++, calling the method empty for the STL adapter queue returns
(a) true if the queue contains no elements
(b) all elements in the queue
(c) the front of the queue if the queue is not empty
(d) an empty queue
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 2.4.2 in the course notes.
4.
Which of the following statements is (are) true about stacks?
1. Elements are inserted and deleted in last-in-first-out order.
2. Stacks can be implemented using linked lists.
3. Stacks can be implemented using arrays.

(a) II and III only


(b) I, II, and III
(c) I and III only
(d) I and II only
Correct answer is

(b)

Your score on this question is:


Feedback:
See section 2.4.1 of the course notes.

10.00

5.
Which of the following operations typically removes an item from a stack?
(a) top
(b) empty
(c) pop
(d) push
Correct answer is

(c)

Your score on this question is:

0.00

Feedback:
See Chapter 7, pages 233C234, in the course textbook.
6.
Which of the following is not a basic operation that can be performed on a queue
?
(a) Accessing an item from the front of the queue
(b) Inserting an item at the back of the queue
(c) Inserting an item into the second position of the queue
(d) Removing an item from the front of the queue
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See Chapter 7, page 236, in the course textbook.
7.
In the C++ standard template library (STL), which of the following is a property
of const iterators for the list container?
(a) Const iterators can be incremented, but never decremented.
(b) They provide read-only access to a linked list.
(c) They provide write-only access to a linked list.
(d) They cannot be used to traverse a linked list.
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 2.2.3 of the course notes.
8.
Consider the following C++ code segment intended to traverse the list L in rever
se order.
list<int>::iterator it;
for( it = L.end(); it != L.begin(); --it ) {
cout << *it << endl;
}
The code segment will not serve the intended purpose because
(a) an attempt is made to access a non-existing list element
(b) there is no decrement operation for list iterators
(c) linked lists in the STL are circular and the loop will never terminate
(d) the identifier it is a keyword
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 2.2.3 of the course notes.
9.
Which of the following statements is (are) true about the locations of a linked
list's nodes in memory?
1. Nodes must appear at a fixed distance from one another in memory.
2. The order of elements in a list must match the order of the list's nodes i
n memory.

(a) I only
(b) I and II
(c) None
(d) II only
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 2.3.1, subsection "A Non-Contiguous List," in the course notes.
10.
To indicate the end of the list, the final node in a typical singly-linked list

stores _____ in place of a _____.


(a) a null pointer, pointer to the previous node
(b) its own address, pointer to the next node
(c) a null pointer, pointer to the next node
(d) its own address, pointer to the previous node
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 2.3.1, subsection "Linking Elements Together," in the course notes.
1.
Consider the following C++ program segment, which uses the STL.
stack<int> X;
X.push(2);
X.push(14);
X.pop();
X.push(37);
X.push(40);
X.pop();
cout << X.top();
What is the output when this program segment is executed?
(a) 14
(b) 2
(c) 37
(d) 40
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 2.4.2 of the course notes.
2.
In C++, calling the method empty for the STL adapter queue returns
(a) all elements in the queue
(b) the front of the queue if the queue is not empty
(c) an empty queue
(d) true if the queue contains no elements
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 2.4.2 in the course notes.
3.
In order to use the adapter queue from the C++ Standard Template Library, which
of the following preprocessor directives is (are) typically required?
1. #include <queue>
2. #include <deque>

(a) None
(b) I only
(c) II only
(d) I and II
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 2.4.2 in the course notes.
4.
Which of the following is (are) typically managed using a stack?
1. Implementation of function calls in a procedural programming language
2. Evaluating arithmetic expressions, taking precedence rules into account
3. Handling jobs sent to a printer, and ensuring that the first jobs to be su
bmitted are printed first

(a) I and III only


(b) II only
(c) I and II only
(d) I, II, and III
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See Chapter 7, pages 235C236, in the course textbook.
5.

Which of the following operations typically removes an item from a stack?


(a) pop
(b) empty
(c) push
(d) top
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See Chapter 7, pages 233C234, in the course textbook.
6.
Which of the following is not a basic operation that can be performed on a queue
?
(a) Removing an item from the front of the queue
(b) Inserting an item into the second position of the queue
(c) Accessing an item from the front of the queue
(d) Inserting an item at the back of the queue
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See Chapter 7, page 236, in the course textbook.
7.
In the C++ standard template library (STL), which of the following is a property
of const iterators for the list container?
(a) Const iterators can be incremented, but never decremented.
(b) They cannot be used to traverse a linked list.
(c) They provide write-only access to a linked list.
(d) They provide read-only access to a linked list.
Correct answer is

(d)

Your score on this question is:


Feedback:
See section 2.2.3 of the course notes.

0.00

8.
Execution of the code fragment
list<int> A(10);
does which of the following?
(a)
ries
(b) Creates
(c) Creates
dom values.
(d) Creates

Creates an empty linked list of ints, but reserves memory for 10 ent
10 linked lists of ints, all initially empty.
a linked list of 10 ints, with each element initially containing ran
a linked list of 10 ints, with each element initially 0.

Correct answer is

(d)

Your score on this question is:

0.00

Feedback:
See section 2.2.3 of the course notes.
9.
The nodes of a _____ linked list can be traversed _____.
(a) singly, forward and backward
(b) doubly, backward only
(c) singly, forward only
(d) doubly, forward only
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 2.3.1, subsection "Linking Elements Together," in the course notes.
10.
A singly linked list is a linked list in which
(a) a single use of the operator new allocates memory for the list
(b) each node contains a pointer to only one other node
(c) elements must contain unique values
(d) elements can contain duplicate values
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 2.3.1, subsection "Linking Elements Together," in the course notes.
1.
Consider the following C++ program segment, which uses the STL.
stack<int,vector<int> > S;
Execution of the statement results in creation of which of the following?
(a) A vector of integer stacks
(b) A stack of integers
(c) A stack of integer vectors
(d) A vector of integers
Correct answer is

(b)

Your score on this question is:

0.00

Feedback:
See section 2.4.2 of the course notes.
2.
An STL adapter provides
(a) a network-socket interface to an STL container
(b) a pointer to an instance of an STL container
(c) a new programming interface for an existing STL container
(d) a wrapper that allows an STL container to be used by the Java programming la
nguage
Correct answer is

(c)

Your score on this question is:

0.00

Feedback:
See section 2.4.2 in the course notes.
3.
Differences between the STL adapter queue and the STL container deque include wh
ich of the following?
1. queue provides support for iterators, whereas deque does not.
2. queue provides access to only the first and last elements in a collection,
whereas deque permits access to an entire collection.

(a) II only
(b) I only
(c) I and II
(d) None
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 2.4.2 in the course notes.
4.
Which of the following data structures uses a "Last-in, First-out" policy for el
ement insertion and removal?
(a) Tree
(b) Queue
(c) Stack
(d) Hash table
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 2.5.1, subsection "Stacks Introduced," in the course notes.
5.
Which of the following operations typically removes an item from a stack?
(a) empty
(b) push
(c) pop
(d) top
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See Chapter 7, pages 233C234, in the course textbook.

6.
Which of the following is not a basic operation that can be performed on a queue
?
(a) Removing an item from the front of the queue
(b) Inserting an item at the back of the queue
(c) Accessing an item from the front of the queue
(d) Inserting an item into the second position of the queue
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See Chapter 7, page 236, in the course textbook.
7.
Execution of the code fragment
list<int> A(10);
does which of the following?
(a)
ning random
(b) Creates
(c) Creates
(d) Creates

Creates a linked list of 10 ints, with each element initially contai


values.
a linked list of 10 ints, with each element initially 0.
10 linked lists of ints, all initially empty.
an empty linked list of ints, but reserves memory for 10 entries

Correct answer is

(b)

Your score on this question is:

0.00

Feedback:
See section 2.2.3 of the course notes.
8.
Consider the following code fragment concerning the STL list class.
list<int> L(10);
L[3] = 555;
The fragment will produce a compile time error because
(a) the class list only supports the const version of the bracket operat
or
(b) the class list does not support a constructor with given length
(c) L is an array of 10 list objects, and we cannot assign 555 to a list object

(d) the class list does not support the bracket operator
Correct answer is

(d)

Your score on this question is:

0.00

Feedback:
See section 2.2.3 of the course notes.
9.
Which of the following operations is (are) typically more efficient in a linked
list than in a vector?
1. Removal of the first element
2. Random element access

(a) None
(b) I only
(c) I and II
(d) II only
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 2.3.1, subsection "A Non-Contiguous List," in the course notes.
10.
The nodes of a _____ linked list can be traversed _____.
(a) singly, forward only
(b) singly, forward and backward
(c) doubly, backward only
(d) doubly, forward only
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 2.3.1, subsection "Linking Elements Together," in the course notes.
1.
Consider the following C++ program segment, which uses the STL.

stack<int,list<int> > S;
Execution of the statement results in creation of which of the following?
(a) A stack of integer lists
(b) A stack of integers
(c) A list of integers
(d) A list of integer stacks
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 2.4.2 of the course notes.
2.
In the C++ Standard Template Library (STL), the class queue is _____ that uses _
____ for storage.
(a) an adapter, a C-style array
(b) a sequence container, a C-style array
(c) a sequence container, an adapter class
(d) an adapter, a sequence container
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See Chapter 7, page 249, in the course textbook.
3.
Differences between the STL adapter queue and the STL container deque include wh
ich of the following?
1. queue provides support for iterators, whereas deque does not.
2. queue provides access to only the first and last elements in a collection,
whereas deque permits access to an entire collection.

(a) I only
(b) II only
(c) I and II
(d) None
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 2.4.2 in the course notes.
4.
Which of the following operations typically removes an item from a stack?
(a) top
(b) push
(c) pop
(d) empty
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See Chapter 7, pages 233C234, in the course textbook.
5.
Which of the following statements is (are) true about stacks?
1. Elements are inserted and deleted in last-in-first-out order.
2. Stacks can be implemented using linked lists.
3. Stacks can be implemented using arrays.

(a) I and III only


(b) I, II, and III
(c) II and III only
(d) I and II only
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 2.4.1 of the course notes.
6.
Which of the following is not a basic operation that can be performed on a queue
?
(a) Accessing an item from the front of the queue
(b) Removing an item from the front of the queue
(c) Inserting an item into the second position of the queue

(d) Inserting an item at the back of the queue


Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See Chapter 7, page 236, in the course textbook.
7.
One thing that the STL vector and the STL list have in common is that bo
th are
(a) inherited from the superclass Container
(b) based on arrays of elements
(c) sequential containers
(d) random access containers
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 2.2.2 of the course notes.
8.
In STL, nodes of a linked list can be accessed using which of the following?
1. STL iterators
2. Subscripts

(a) I only
(b) I and II
(c) None
(d) II only
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 2.2.3 of the course notes.
9.
Which of the following operations is (are) typically more efficient in a linked
list than in a vector?
1. Removal of the first element
2. Random element access

(a) I and II
(b) None
(c) I only
(d) II only
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 2.3.1, subsection "A Non-Contiguous List," in the course notes.
10.
Which of the following is (are) typically true about linked lists?
1. Objects in a linked list are stored contiguously in memory.
2. All elements in a list are copied to new locations in memory upon frontal
insertions to the list.

(a) None
(b) I and II
(c) I only
(d) II only
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 2.3.1 in the course notes.
1.
Consider the following C++ program segment, which uses the STL.
stack<int> X;
X.push(2);
X.push(14);
X.pop();
X.push(37);
X.push(40);
X.pop();
cout << X.top();
What is the output when this program segment is executed?
(a) 2
(b) 40

(c) 14
(d) 37
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 2.4.2 of the course notes.
2.
An STL adapter provides
(a) a network-socket interface to an STL container
(b) a wrapper that allows an STL container to be used by the Java programming la
nguage
(c) a pointer to an instance of an STL container
(d) a new programming interface for an existing STL container
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 2.4.2 in the course notes.
3.
Which of the following is a method (are methods) available in the class queue in
the C++ Standard Template Library?
1. push
2. pop
3. enqueue

(a) I and II only


(b) I, II, and III
(c) None
(d) III only
Correct answer is

(a)

Your score on this question is:


Feedback:

10.00

See Chapter 7, page 249, in the course textbook.


4.

Which of the following data structures uses a "Last-in, First-out" policy for el
ement insertion and removal?
(a) Stack
(b) Tree
(c) Hash table
(d) Queue
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 2.5.1, subsection "Stacks Introduced," in the course notes.
5.
Which of the following operations typically removes an item from a stack?
(a) top
(b) push
(c) pop
(d) empty
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See Chapter 7, pages 233C234, in the course textbook.
6.
Which of the following linear data structures use a first-in, first-out element
insertion and removal policy?
1. Stacks
2. Queues

(a) I only
(b) None
(c) I and II
(d) II only
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See sections 2.4.1 and 2.5.1 in the course notes.
7.
Typical implementations for which of the following STL containers store elements
contiguously in memory?
1. vector
2. list

(a) I and II
(b) I only
(c) II only
(d) None
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 2.3.1, subsection "A Non-contiguous List," in the course notes.
8.
Execution of the code fragment
list<int> A(10);
does which of the following?
(a)
Creates
Creates
Creates
values.

(b)
(c)
(d)
dom

Creates a linked list of 10 ints, with each element initially 0.


10 linked lists of ints, all initially empty.
an empty linked list of ints, but reserves memory for 10 entries
a linked list of 10 ints, with each element initially containing ran

Correct answer is

(a)

Your score on this question is:


Feedback:
See section 2.2.3 of the course notes.
9.

10.00

Which of the following pointers is (are) stored by nodes in a doubly-linked list


?
1. A pointer to the next node
2. A pointer to the previous node

(a) I only
(b) I and II
(c) None
(d) II only
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 2.3.1, subsection "Linking Elements Together," in the course notes.
10.
To indicate the end of the list, the final node in a typical singly-linked list
stores _____ in place of a _____.
(a) its own address, pointer to the previous node
(b) a null pointer, pointer to the previous node
(c) a null pointer, pointer to the next node
(d) its own address, pointer to the next node
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 2.3.1, subsection "Linking Elements Together," in the course notes.
1.
Consider the following C++ program segment, which uses the STL.
stack<int,vector<int> > S;
Execution of the statement results in creation of which of the following?
(a) A stack of integer vectors
(b) A vector of integers
(c) A vector of integer stacks
(d) A stack of integers
Correct answer is

(d)

Your score on this question is:

0.00

Feedback:
See section 2.4.2 of the course notes.
2.
An STL adapter provides
(a) a network-socket interface to an STL container
(b) a pointer to an instance of an STL container
(c) a new programming interface for an existing STL container
(d) a wrapper that allows an STL container to be used by the Java programming la
nguage
Correct answer is

(c)

Your score on this question is:

0.00

Feedback:
See section 2.4.2 in the course notes.
3.
In the C++ Standard Template Library (STL), the class queue is _____ that uses _
____ for storage.
(a) an adapter, a
(b) a sequence container,
(c) an adapter, a C-style
(d) a sequence container,
Correct answer is

sequence container
an adapter class
array
a C-style array
(a)

Your score on this question is:

10.00

Feedback:
See Chapter 7, page 249, in the course textbook.
4.
Which of the following is (are) typically managed using a stack?
1. Implementation of function calls in a procedural programming language
2. Evaluating arithmetic expressions, taking precedence rules into account
3. Handling jobs sent to a printer, and ensuring that the first jobs to be su
bmitted are printed first

(a) I and III only


(b) I, II, and III
(c) I and II only
(d) II only
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See Chapter 7, pages 235C236, in the course textbook.
5.
Which of the following statements is (are) true about stacks?
1. Elements are inserted and deleted in last-in-first-out order.
2. Stacks can be implemented using linked lists.
3. Stacks can be implemented using arrays.

(a) I and II only


(b) II and III only
(c) I and III only
(d) I, II, and III
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 2.4.1 of the course notes.
6.
Consider the following sequence of operations applied to an empty queue:
Insert
Insert
Remove
Insert
Remove
Insert

element
element
element
element
element
element

with value 3
with value 8
with value 1
with value 7

The next element removed from this queue will have which of the following values
?
(a) 3
(b) 1
(c) 8
(d) 7

Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 2.4.1 in the course notes.
7.
Execution of the code fragment
list<int> A(10);
does which of the following?
(a)
ning random
(b) Creates
(c) Creates
(d) Creates

Creates a linked list of 10 ints, with each element initially contai


values.
10 linked lists of ints, all initially empty.
an empty linked list of ints, but reserves memory for 10 entries
a linked list of 10 ints, with each element initially 0.

Correct answer is

(d)

Your score on this question is:

0.00

Feedback:
See section 2.2.3 of the course notes.
8.
One thing that the STL vector and the STL list have in common is that bo
th are
(a) based on arrays of elements
(b) random access containers
(c) inherited from the superclass Container
(d) sequential containers
Correct answer is

(d)

Your score on this question is:

0.00

Feedback:
See section 2.2.2 of the course notes.
9.
To indicate the end of the list, the final node in a typical singly-linked list
stores _____ in place of a _____.
(a) a null pointer, pointer to the previous node
(b) its own address, pointer to the previous node
(c) its own address, pointer to the next node

(d) a null pointer, pointer to the next node


Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 2.3.1, subsection "Linking Elements Together," in the course notes.
10.
The nodes of a _____ linked list can be traversed _____.
(a) doubly, backward only
(b) singly, forward only
(c) singly, forward and backward
(d) doubly, forward only
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 2.3.1, subsection "Linking Elements Together," in the course notes.
1.
Consider the following C++ program segment, which uses the STL.
stack<int> S;
S.push(123);
S.push(456);
cout << S.pop() << endl;
Which of the following accurately describes what, if anything, fails in the segm
ent?

(a) A compilation error occurs because pop does not return a value.
(b) An execution error occurs because an STL stack has no member function pop.
(c) Nothing is wrong with the segment.
(d) An execution error occurs because pop is a private member function.
Correct answer is (a)
8.
Consider the execution of the following.
list<int> A(10,20);
Which of the following accurately describes what is created?

(a) A linked list of size 10, each containing 10 arrays of ints of size 20
(b) a linked list of 10 linked lists, each containing 20 ints
(c) A linked list of 10 ints, with each element initially 20
(d) An array of size 20 of linked list, each containing 20 ints
Correct answer is (c)
Your score on this question is: 10.00
Feedback:
See section 2.2.3 of the course notes.
-------------------------------------------------------------------------------9.
To access an element in a singly linked list, a program must

(a) allocate memory for temporary nodes


(b) traverse all nodes in the list prior to that element
(c) add the element's index to the memory address of the first element in the l
ist
(d) compute a hash value for the element
Correct answer is (b)
Your score on this question is: 10.00
2.
The queue adapter interface in the C++ Standard Template Library contains which
of the following member functions?
push
pop_back

(a) II only
(b) I only
(c) None
(d) I and II
Correct answer is (b)
Your score on this question is: 10.00
7.
Consider the following code fragment, where L is a linked list of integers.
for( it = L.begin(); it != L.end(); ++it )
*it += 10;
Execution of this fragment has the effect of

(a) stepping through the lists in increments of 10


(b) adding 10 to each list element

(c) inserting a new element 10 after each list element


(d) appending 10 to the list
Correct answer is (b)
Your score on this question is: 10.00
View Assessment Result: Multiple-Choice Quiz 5

Your performance was as follows:


1.
Consider the following C++ program segment, which uses the STL.
stack<int> X;
X.push(2);
X.push(14);
X.pop();
X.push(37);
X.push(40);
X.pop();
cout << X.top();
What is the output when this program segment is executed?

(a) 37
(b) 14
(c) 40
(d) 2
Correct answer is (a)
Your score on this question is: 0.00
Feedback:
See section 2.4.2 of the course notes.
-------------------------------------------------------------------------------2.
The queue adapter interface in the C++ Standard Template Library contains which
of the following member functions?
push
pop_back

(a) I and II
(b) I only
(c) None
(d) II only
Correct answer is (b)

Your score on this question is: 0.00


Feedback:
See section 2.4.2 in the course notes.

-------------------------------------------------------------------------------3.
Differences between the STL adapter queue and the STL container deque include w
hich of the following?
queue provides support for iterators, whereas deque does not.
queue provides access to only the first and last elements in a collection, where
as deque permits access to an entire collection.

(a) I and II
(b) II only
(c) I only
(d) None
Correct answer is (b)
Your score on this question is: 0.00
Feedback:
See section 2.4.2 in the course notes.

-------------------------------------------------------------------------------4.
Which of the following is (are) typically managed using a stack?
Implementation of function calls in a procedural programming language
Evaluating arithmetic expressions, taking precedence rules into account
Handling jobs sent to a printer, and ensuring that the first jobs to be submitte
d are printed first

(a) I and II only


(b) I, II, and III
(c) II only
(d) I and III only
Correct answer is (a)
Your score on this question is: 0.00
Feedback:
See Chapter 7, pages 235C236, in the course textbook.

-------------------------------------------------------------------------------5.
Which of the following statements is (are) true about stacks?
Elements are inserted and deleted in last-in-first-out order.
Stacks can be implemented using linked lists.
Stacks can be implemented using arrays.

(a) I and III only


(b) II and III only
(c) I and II only
(d) I, II, and III
Correct answer is (d)
Your score on this question is: 10.00
Feedback:
See section 2.4.1 of the course notes.
-------------------------------------------------------------------------------6.
Which of the following is not a basic operation that can be performed on a queu
e?

(a) Inserting an item at the back of the queue


(b) Accessing an item from the front of the queue
(c) Removing an item from the front of the queue
(d) Inserting an item into the second position of the queue
Correct answer is (d)
Your score on this question is: 10.00
Feedback:
See Chapter 7, page 236, in the course textbook.

-------------------------------------------------------------------------------7.
One thing that the STL vector and the STL list have in common is that both are
(a) inherited from the superclass Container
(b) random access containers
(c) based on arrays of elements
(d) sequential containers

Correct answer is (d)


Your score on this question is: 10.00
Feedback:
See section 2.2.2 of the course notes.
-------------------------------------------------------------------------------8.
Typical implementations for which of the following STL containers store element
s contiguously in memory?
vector
list

(a) I only
(b) None
(c) I and II
(d) II only
Correct answer is (a)
Your score on this question is: 0.00
Feedback:
See section 2.3.1, subsection "A Non-contiguous List," in the course notes.

-------------------------------------------------------------------------------9.
To access an element in a singly linked list, a program must

(a) allocate memory for temporary nodes


(b) traverse all nodes in the list prior to that element
(c) compute a hash value for the element
(d) add the element's index to the memory address of the first element in the l
ist
Correct answer is (b)
Your score on this question is: 0.00
Feedback:
See section 2.3.1 in the course notes.

--------------------------------------------------------------------------------

10.
Which of the following statements is (are) true about the locations of a linked
list's nodes in memory?
Nodes must appear at a fixed distance from one another in memory.
The order of elements in a list must match the order of the list's nodes in memo
ry.

(a) I only
(b) II only
(c) None
(d) I and II
Correct answer is (c)
Your score on this question is: 10.00
Feedback:
See section 2.3.1, subsection "A Non-Contiguous List," in the course notes.

-------------------------------------------------------------------------------View Assessment Result: Multiple-Choice Quiz 5

Your performance was as follows:


1.
Consider the following C++ program segment, which uses the STL.
stack<int,vector<int> > S;
Execution of the statement results in creation of which of the following?

(a) A stack of integer vectors


(b) A vector of integers
(c) A stack of integers
(d) A vector of integer stacks
Correct answer is (c)
Your score on this question is: 10.00
Feedback:
See section 2.4.2 of the course notes.
-------------------------------------------------------------------------------2.

An STL adapter provides

(a) a pointer to an instance of an STL container


(b) a network-socket interface to an STL container
(c) a new programming interface for an existing STL container
(d) a wrapper that allows an STL container to be used by the Java programming l
anguage
Correct answer is (c)
Your score on this question is: 0.00
Feedback:
See section 2.4.2 in the course notes.

-------------------------------------------------------------------------------3.
In C++, calling the method empty for the STL adapter queue returns

(a) true if the queue contains no elements


(b) the front of the queue if the queue is not empty
(c) an empty queue
(d) all elements in the queue
Correct answer is (a)
Your score on this question is: 10.00
Feedback:
See section 2.4.2 in the course notes.

-------------------------------------------------------------------------------4.
Which of the following is (are) typically managed using a stack?
Implementation of function calls in a procedural programming language
Evaluating arithmetic expressions, taking precedence rules into account
Handling jobs sent to a printer, and ensuring that the first jobs to be submitte
d are printed first

(a) I, II, and III


(b) I and III only
(c) I and II only
(d) II only
Correct answer is (c)

Your score on this question is: 10.00


Feedback:
See Chapter 7, pages 235C236, in the course textbook.

-------------------------------------------------------------------------------5.
Which of the following statements is (are) true about stacks?
Elements are inserted and deleted in last-in-first-out order.
Stacks can be implemented using linked lists.
Stacks can be implemented using arrays.

(a) II and III only


(b) I, II, and III
(c) I and III only
(d) I and II only
Correct answer is (b)
Your score on this question is: 10.00
Feedback:
See section 2.4.1 of the course notes.
-------------------------------------------------------------------------------6.
Which of the following is not a basic operation that can be performed on a queu
e?

(a) Inserting an item into the second position of the queue


(b) Removing an item from the front of the queue
(c) Accessing an item from the front of the queue
(d) Inserting an item at the back of the queue
Correct answer is (a)
Your score on this question is: 10.00
Feedback:
See Chapter 7, page 236, in the course textbook.

-------------------------------------------------------------------------------7.
Typical implementations for which of the following STL containers store element

s contiguously in memory?
vector
list

(a) None
(b) I only
(c) II only
(d) I and II
Correct answer is (b)
Your score on this question is: 10.00
Feedback:
See section 2.3.1, subsection "A Non-contiguous List," in the course notes.

-------------------------------------------------------------------------------8.
In STL, nodes of a linked list can be accessed using which of the following?
STL iterators
Subscripts

(a) I and II
(b) I only
(c) None
(d) II only
Correct answer is (b)
Your score on this question is: 10.00
Feedback:
See section 2.2.3 of the course notes.
-------------------------------------------------------------------------------9.
Which of the following pointers is (are) stored by nodes in a doubly-linked lis
t?
A pointer to the next node
A pointer to the previous node

(a) None
(b) II only
(c) I only
(d) I and II

Correct answer is (d)


Your score on this question is: 10.00
Feedback:
See section 2.3.1, subsection "Linking Elements Together," in the course notes.

-------------------------------------------------------------------------------10.
Which of the following statements is (are) true about the locations of a linked
list's nodes in memory?
Nodes must appear at a fixed distance from one another in memory.
The order of elements in a list must match the order of the list's nodes in memo
ry.

(a) None
(b) I only
(c) II only
(d) I and II
Correct answer is (a)
Your score on this question is: 10.00
Feedback:
See section 2.3.1, subsection "A Non-Contiguous List," in the course notes.

-------------------------------------------------------------------------------Go to top of assessment.


Total score: 90.00
? Copyright 2004 iCarnegie, Inc. All rights reserved.
View Assessment Result: Multiple-Choice Quiz 6

Your performance was as follows:


1.
Consider the following definition of a recursive function ff in C++.
int ff( int n, int m )
{

if( n == 0 ) return m;
return ff( n - 1, m + 1 );
}
Which of the following characterizes the value returned by the call f(n,m)?

(a) The sum of m and n


(b) The greatest common divisor of m and n
(c) The product of m and n
(d) The least common multiple of m and n
Correct answer is (a)
Your score on this question is: 0.00
Feedback:
See section 3.1.1 of the course notes.
-------------------------------------------------------------------------------2.
What would be the consequences for algorithms if recursion were removed from C+
+?
(a) Some algorithms could no longer be implemented.
(b) All algorithms could still be implemented, but the efficiency would often b
e catastrophically worse.
(c) None
(d) All algorithms could still be implemented, but often less elegantly.
Correct answer is (d)
Your score on this question is: 0.00
Feedback:
See section 3.1.1 of the course notes.
-------------------------------------------------------------------------------3.
Consider the following definition of a recursive function f.
bool f( int x )
{
if( (x & 1) == 1 ) return (x == 1);
return f( x >> 1 );
// right shift
}
The value returned by the call f(x) will determine whether the input x is

(a) odd
(b) a power of 2
(c) even
(d) a prime

Correct answer is (b)


Your score on this question is: 0.00
Feedback:
See section 3.1.1 of the course notes.
-------------------------------------------------------------------------------4.
Consider the following definition of a recursive function f.
int f( int x )
{
if( x == 0 ) return 1;
return x * f( x - 1 );
}
The inputs for which f will terminate are all x such that x is

(a) non-negative
(b) even
(c) odd
(d) unrestricted
Correct answer is (a)
Your score on this question is: 0.00
Feedback:
See section 3.1.1 of the course notes.
-------------------------------------------------------------------------------5.
Consider the following definition of a recursive function f.
int f( int x )
{
if( x == 0 ) return 1;
return x * f( x );
}
For which inputs x will the call f(x) terminate?

(a) For all odd inputs x only


(b) For all inputs x
(c) For all even inputs x only
(d) For x = 0 only
Correct answer is (d)
Your score on this question is: 0.00

Feedback:
See section 3.1.1 of the course notes.
-------------------------------------------------------------------------------6.
Which of the following is the main reason for using recursion?
(a) To obtain short, elegant solutions
(b) To use less memory
(c) To avoid templates and inheritance
(d) To improve efficiency
Correct answer is (a)
Your score on this question is: 0.00
Feedback:
See section 3.1.1 of the course notes.
-------------------------------------------------------------------------------7.
Which of the following is (are) true of recursive algorithms and the backtracki
ng problem-solving technique?
Recursive algorithms implement backtracking by reducing a problem into smaller a
nd smaller sub-problems.
Recursive algorithms cannot be used to implement backtracking.
Recursive algorithms that implement backtracking do not typically have a base ca
se.

(a) I and III only


(b) None
(c) I only
(d) II only
Correct answer is (c)
Your score on this question is: 0.00
Feedback:
See section 3.2.2 in the course notes.

-------------------------------------------------------------------------------8.
Using a backtracking technique to solve a problem typically involves

(a) using concurrency to check several possible solutions simultaneously


(b) using a breadth-first strategy to search the problem space
(c) starting with the set of all possible solutions and working backwards from
each to determine which is the actual solution
(d) pursuing a possible solution until it is found to be a solution or a non-so
lution
Correct answer is (d)
Your score on this question is: 0.00
Feedback:
See section 3.2.2 in the course notes.

-------------------------------------------------------------------------------9.
A divide-and-conquer algorithm typically makes use of

(a) iteration through looping


(b) floating-point division
(c) integer division
(d) recursion
Correct answer is (d)
Your score on this question is: 10.00
Feedback:
See Chapter 8, pages 292C293, in the course textbook.

-------------------------------------------------------------------------------10.
Which of the following statements is (are) typical of divide and conquer algori
thms?
Recursive function calls are used to divide a problem into smaller and smaller s
ub-problems.
Concurrent programming is used to divide the necessary processing between multip
le processors.

(a) I only
(b) I and II
(c) None
(d) II only
Correct answer is (a)
Your score on this question is: 10.00

Feedback:
See section 3.2.1 in the course notes.

--------------------------------------------------------------------------View Assessment Result: Multiple-Choice Quiz 6

Your performance was as follows:


1.
Consider the following definition of a recursive function ff.
int ff( int n )
{
if( n == 0 ) return 1;
return 2 * ff( n - 1 );
}
If n > 0, what is returned by ff( n )?

(a) log2 n
(b) 2n
(c) 2 * n
(d) n2
Correct answer is (b)
Your score on this question is: 10.00
Feedback:
See section 3.1.1 of the course notes.
-------------------------------------------------------------------------------2.
Which of the following is the main reason for using recursion?
(a) To improve efficiency
(b) To avoid templates and inheritance
(c) To use less memory
(d) To obtain short, elegant solutions
Correct answer is (d)
Your score on this question is: 10.00
Feedback:
See section 3.1.1 of the course notes.

-------------------------------------------------------------------------------3.
Consider the following definition of a recursive function ff in C++.
int ff( int n, int m )
{
if( n == 0 ) return 0;
return ff( n - 1, m ) + m;
}
Which of the following characterizes the value returned by the call f(n,m)?

(a) The least common multiple of m and n


(b) The sum of m and n
(c) The product of m and n
(d) The greatest common divisor of m and n
Correct answer is (c)
Your score on this question is: 0.00
Feedback:
See section 3.1.1 of the course notes.
-------------------------------------------------------------------------------4.
How many calls to itself is a recursive function allowed to make?
(a) None
(b) At most two
(c) Any number
(d) At most one
Correct answer is (c)
Your score on this question is: 10.00
Feedback:
See section 3.1.1 of the course notes.
-------------------------------------------------------------------------------5.
Consider the following definition of a recursive function f.
bool f( int x )
{
if( (x & 1) == 1 ) return (x == 1);
return f( x >> 1 );
// right shift
}
The value returned by the call f(x) will determine whether the input x is

(a) even
(b) odd
(c) a prime
(d) a power of 2
Correct answer is (d)
Your score on this question is: 10.00
Feedback:
See section 3.1.1 of the course notes.
-------------------------------------------------------------------------------6.
Consider the following definition of a recursive function ff in C++.
int ff( int n, int m )
{
if( n == 0 ) return m;
return ff( n - 1, m + 1 );
}
Which of the following characterizes the value returned by the call f(n,m)?

(a) The greatest common divisor of m and n


(b) The product of m and n
(c) The least common multiple of m and n
(d) The sum of m and n
Correct answer is (d)
Your score on this question is: 10.00
Feedback:
See section 3.1.1 of the course notes.
-------------------------------------------------------------------------------7.
A backtracking algorithm is one that

(a) uses a binary search to solve a problem


(b) uses recursion to test all possible solutions for a problem
(c) uses loops to iterate through all possible solutions for a problem
(d) splits a problem into two equal halves and uses recursion to solve each hal
f
Correct answer is (b)
Your score on this question is: 0.00
Feedback:

See Chapter 8, page 308, in the course textbook.

-------------------------------------------------------------------------------8.
Which of the following is (are) true of recursive algorithms and the backtracki
ng problem-solving technique?
Recursive algorithms implement backtracking by reducing a problem into smaller a
nd smaller sub-problems.
Recursive algorithms cannot be used to implement backtracking.
Recursive algorithms that implement backtracking do not typically have a base ca
se.

(a) I only
(b) I and III only
(c) None
(d) II only
Correct answer is (a)
Your score on this question is: 10.00
Feedback:
See section 3.2.2 in the course notes.

-------------------------------------------------------------------------------9.
A divide-and-conquer algorithm typically makes use of

(a) integer division


(b) floating-point division
(c) iteration through looping
(d) recursion
Correct answer is (d)
Your score on this question is: 10.00
Feedback:
See Chapter 8, pages 292C293, in the course textbook.

-------------------------------------------------------------------------------10.
Which of the following statements is (are) typical of divide and conquer algori

thms?
Recursive function calls are used to divide a problem into smaller and smaller s
ub-problems.
Concurrent programming is used to divide the necessary processing between multip
le processors.

(a) I and II
(b) I only
(c) None
(d) II only
Correct answer is (b)
Your score on this question is: 10.00
Feedback:
See section 3.2.1 in the course notes.

-------------------------------------------------------------------------------2.
Consider the following definition of a recursive function ff.
int ff( int n )
{
if( n == 0 ) return 1;
return 2 * ff( n - 1 );
}
If n > 0, what is returned by ff( n )?

(a) 2n
(b) 2 * n
(c) log2 n
(d) n2
Correct answer is (a)
Your score on this question is: 10.00
Feedback:
See section 3.1.1 of the course notes.
-------------------------------------------------------------------------------3.
Consider the function defined as follows.
int f( int n )
{

if( n == 0 ) return 0;
if( (n & 1) == 0 ) return f(n/2);
return f(n/2) + 1;
}
The value returned by the call f( 10 ); is

(a) 2
(b) 1
(c) 5
(d) 3
Correct answer is (a)
Your score on this question is: 0.00
Feedback:
See section 3.1.1 of the course notes.

-------------------------------------------------------------------------------7.
Which of the following is (are) true of the minimax strategy for deciding the o
ptimal move in a two-person game?
It assumes that a human player will eventually make a mistake by playing a move
that is not optimal.
It is commonly used with a backtracking algorithm.

(a) II only
(b) None
(c) I only
(d) I and II
Correct answer is (a)
Your score on this question is: 10.00
Feedback:
See Chapter 8, pages 308C310, in the course textbook.

-------------------------------------------------------------------------------9.
What is the runtime overhead of a divide-and-conquer algorithm that recursively
processes two equal halves of a problem that each have an overhead of O(n)?

(a) O(2n)
(b) O(n2)

(c) O(log n)
(d) O(n log n)
Correct answer is (d)
Your score on this question is: 10.00
Feedback:
See Chapter 8, page 301, in the course textbook.

-------------------------------------------------------------------------------10.
Typical divide and conquer algorithms use _____ to divide a problem into smalle
r sub-problems. The _____ typically solve(s) these sub-problems directly.

(a) inheritance, methods of the child class


(b) recursive function calls, base case of the recursion
(c) iteration, body of the loop
(d) a process scheduler, individual processes
Correct answer is (b)
Your score on this question is: 10.00
1.
A program cannot accidentally "crash" a computer that uses
1. virtual memory addresses
2. program relocation
3. separate instruction and data caches.

(a) I and II only


(b) I only
(c) III only
(d) II and III only
Correct answer is

(b)

Your score on this question is:

16.67

Feedback:
See section 5.3.1 of the course notes.
2.
Compared to static RAM (SRAM), dynamic RAM (DRAM) is
1. more expensive per megabyte.
2. slower per word access.
3. more persistent.

(a) I only.
(b) II only.
(c) I and III only.
(d) II and III only.
Correct answer is

(b)

Your score on this question is:

16.67

Feedback:
See section 5.1.1 of the course notes.
3.
A certain program is found to execute with a cache hit ratio of 0.90 on
computer A, and of 0.95 on computer B. However, because of other design paramete
rs of these computers, its wall time is the same in both A and B. Then, a clever
programmer finds a way to improve the locality of the program, so that it now e
xecutes with a hit ratio of 0.92 on A, and of 0.97 on B. Which of the following
statements is valid?
(a) The wall time is still the same on A and B, though it is smaller tha
n before on both of them.
(b) The wall time is now greater on B than on A.
(c) It is impossible to change the hit ratio of a program.
(d) The wall time is now smaller on B than on A.
Correct answer is

(d)

Your score on this question is:

16.67

Feedback:
See section 5.1.3 of the course notes.
4.
A memory hierarchy
(a) is a way of structuring memory allocation decisions.
(b) limits programs' size but allows them to execute more quickly.
(c) takes advantage of the speed of SRAM and the capacity of disk.
(d) makes programs execute more slowly but allows them to be bigger.
Correct answer is

(c)

Your score on this question is:

16.67

Feedback:
See section 5.1.1 of the course notes.
5.
Your computer has 32-bit integers and a direct cache containing 128 32-b
yte cache lines. In the following code fragment, the compiler allocates a at add
ress 0x800000 and b at address 0x801000. Before the execution of the code fragme
nt, the arrays a and b have never been used, so they are not in the cache. What
is the minimum number of bytes from each of the arrays a and b that could be fet
ched into the cache from main memory, during the execution of the code?
int b[1024];
int a[1024];
for (i = 0; i < 17; sum += a[i] + b[i], i++);

(a) 1088
(b) 68
(c) 96
(d) 17
Correct answer is

(a)

Your score on this question is:

16.67

Feedback:
See section 5.2.1 of the course notes.
6.
Consider the following fragments from two versions of a program.
Version A
Version B
for (i = 0 ; i < N ; i++ ) {
Read(i);
Calculate(i);
Write(i);
}

for (i = 0 ; i < N ; i++ ) {


Read(i);
}
for (i = 0 ; i < N ; i++ ) {
Calculate(i);
}
for (i = 0 ; i < N ; i++ ) {
Write(i);
}
}
Which of the following are true of version B, compared to version A?
1. B may be faster because of cache effects.
2. B may be slower because of cache effects.
3. B may execute at essentially the same speed as A.

(a) I only
(b) I, II, and III
(c) II and III only
(d) I and III only
Correct answer is

(b)

Your score on this question is:


Feedback:
See section 5.2.4 of the course notes.
View Assessment Result: Multiple-Choice Quiz 5

16.67

Your performance was as follows:


1.
A program cannot accidentally "crash" a computer that uses
virtual memory addresses
program relocation
separate instruction and data caches.

(a) III only


(b) II and III only
(c) I only
(d) I and II only
Correct answer is (c)
Your score on this question is: 16.67
Feedback:
See section 5.3.1 of the course notes.
-------------------------------------------------------------------------------2.
The 200MHz intel-based processor of a computer with no cache is upgraded to a 5
00 MHz version of the same processor. On the average, programs now run
(a) at about the same speed.
(b) about 150% faster.
(c) about 100% faster (about 1/3 of the memory accesses are instruction fetches
).
(d) faster on the internet than off it.
Correct answer is (a)
Your score on this question is: 0.00
Feedback:
See section 5.1.3 of the course notes.
-------------------------------------------------------------------------------3.
Which of the following is (are) true of the concept of locality of reference?
It is used to predict future memory references precisely, with the help of the c
ompiler.
It is a quality of typical programs.
It has been mathematically proven.

(a) I only

(b) II only
(c) I and II only
(d) II and III only
Correct answer is (b)
Your score on this question is: 0.00
Feedback:
See section 5.1.2 of the course notes.
-------------------------------------------------------------------------------4.
A memory hierarchy
(a) is a way of structuring memory allocation decisions.
(b) limits programs' size but allows them to execute more quickly.
(c) makes programs execute more slowly but allows them to be bigger.
(d) takes advantage of the speed of SRAM and the capacity of disk.
Correct answer is (d)
Your score on this question is: 16.67
Feedback:
See section 5.1.1 of the course notes.
-------------------------------------------------------------------------------5.
When the following code fragment is executed on a computer with 32-bit integers
and a fully-associative cache with 32-byte cache lines, how many bytes of the a
rray a will be fetched into the cache from main memory?
int a[100];
for (i = 0; i < 17; sum += a[i], i++);

(a) exactly 32.


(b) at most 96.
(c) at most 68.
(d) exactly 17.
Correct answer is (b)
Your score on this question is: 0.00
Feedback:
See section 5.2.1 of the course notes.
-------------------------------------------------------------------------------6.
Consider the following fragments from two versions of a program. Version A Ver

sion B
for (i = 0 ; i < N ; i++ ) {
Read(i);
Calculate(i);
Write(i);
}
for (i = 0 ; i < N ; i++ ) {
Read(i);
}
for (i = 0 ; i < N ; i++ ) {
Calculate(i);
}
for (i = 0 ; i < N ; i++ ) {
Write(i);
}
}
Which
B may
B may
B may

of the following are true of version B, compared to version A?


be faster because of cache effects.
be slower because of cache effects.
execute at essentially the same speed as A.

(a) I, II, and III


(b) I only
(c) I and III only
(d) II and III only
Correct answer is (a)
Your score on this question is: 16.67
Feedback:
See section 5.2.4 of the course notes.
-------------------------------------------------------------------------------Go to top of assessment.
Total score: 50.00
? Copyright 2005 iCarnegie, Inc. All rights reserved.
1.
Time-sharing occurs when
(a) more than one program executes concurrently on a single computer.
(b) one program must terminate before the next program can run.
(c) there is not enough memory to run all the applications that have been starte
d.
(d) clocks are properly synchronized in a network of computers.
Correct answer is

(a)

Your score on this question is:

25.00

Feedback:
See section 6.2.1 of the course notes.
2.
Polling is undesirable in a time-shared operating system because
(a) it wastes time that could be used to do useful work.
(b) it is too complicated to implement
(c) it leads to interference between two applications accessing the same resourc
e.
(d) it makes programs much larger.
Correct answer is

(a)

Your score on this question is:

25.00

Feedback:
See section 6.2.2 of the course notes.
3.
In a real-time application, a time-critical task should be performed by
(a) a low-priority thread.
(b) the next available thread.
(c) a high-priority thread.
(d) a set of concurrent threads.
Correct answer is

(c)

Your score on this question is:

0.00

Feedback:
See section 6.3.2 of the course notes.
4.
For which of the following applications are threads well suited?
1. Background processing such as data compression or spell-checking
2. Displaying a web page on the screen before it has fully arrived from the s
erver
3. Fetching a page of a web document while the user scrolls through the previ
ous one

(a) II only
(b) I, II, and III
(c) I and II only
(d) I only
Correct answer is

(b)

Your score on this question is:


Feed
1.
Time-sharing occurs when

25.00

(a) one program must terminate before the next program can run.
(b) clocks are properly synchronized in a network of computers.
(c) there is not enough memory to run all the applications that have been starte
d.
(d) more than one program executes concurrently on a single computer.
Correct answer is

(d)

Your score on this question is:

0.00

Feedback:
See section 6.2.1 of the course notes.
2.
When a context switch occurs,
(a) the contents of the cache are mostly irrelevant.
(b) the cache contents must be saved along with the processor registers.
(c) the cache must be disabled.
(d) the contents of the cache are vital for performance.
Correct answer is

(a)

Your score on this question is:

25.00

Feedback:
See section 6.2.3 of the course notes.
3.
Which of these are properties of threads?
1. Only processes with special privileges can create threads.
2. Threads eliminate the need to change address spaces in a context switch.
3. Threads share memory.

(a) II and III only


(b) I, II, and III
(c) II only
(d) I and III only
Correct answer is

(a)

Your score on this question is:

0.00

Feedback:
See section 6.3.1 of the course notes.
4.
For which of the following applications are threads well suited?
1. Background processing such as data compression or spell-checking
2. Displaying a web page on the screen before it has fully arrived from the s
erver
3. Fetching a page of a web document while the user scrolls through the previ
ous one

(a) I and II only


(b) I, II, and III
(c) II only
(d) I only
Correct answer is

(b)

Your score on this question is:

0.00

Feedba
1.
When a context switch occurs,
(a) the contents of the cache are vital for performance.
(b) the contents of the cache are mostly irrelevant.
(c) the cache contents must be saved along with the processor registers.
(d) the cache must be disabled.
Correct answer is

(b)

Your score on this question is:

0.00

Feedback:
See section 6.2.3 of the course notes.
2.
In modern operating systems, the malicious behavior of one program shoul
d not have any harmful effects on other programs. Which of the following mechani
sms support(s) this kind of protection?
1. Separate address spaces for each application process
2. Preemptive scheduling administered by the operating system
3. Free access to input/output device so that they cannot be hoarded

(a) I and III only


(b) I only
(c) I, II, and III
(d) I and II only
Correct answer is

(d)

Your score on this question is:

25.00

Feedback:
See section 6.2.2 of the course notes.
3.
Priority inversion is a situation in which
(a) long-running processes are assigned lower priorities.
(b) threads with the earliest deadlines receive higher priorities.
(c) the scheduler reverses priorities to prevent starvation of low-priority thre
ads.
(d) a high-priority thread indirectly waits on a lower priority thread.
Correct answer is

(d)

Your score on this question is:

0.00

Feedback:
See section 6.3.5 of the course notes.
4.
A reentrant function can be entered
(a) only once before variables are reinitialized
(b) multiple times but only by one thread at a time
(c) at several points, not only the top
(d) concurrently by more than one thread
Correct answer is

(d)

Your score on this question is:

25.00

Feedb
1.
Which of the following are effects of a page fault in the program that c
aused it by, e.g, reading the value of a variable?
1. An exception is thrown.
2. A delay occurs.
3. The program is terminated.

(a) I and III only


(b) II only
(c) II and III only
(d) I and II only
Correct answer is

(d)

Your score on this question is:

0.00

Feedback:
See section 5.3.2 of the course notes.
2.
Which of the following is (are) true of the concept of locality of refer
ence?
1. It is used to predict future memory references precisely, with the help of
the compiler.
2. It is a quality of typical programs.
3. It has been mathematically proven.

(a) I only
(b) II and III only
(c) I and II only
(d) II only
Correct answer is

(d)

Your score on this question is:

16.67

Feedback:
See section 5.1.2 of the course notes.
3.
Current technology trends suggest that the need for memory hierarchies
(a) will disappear when "broadband" communications start delivering data
over the internet at speeds greater than 1Mbps.
(b) will never disappear.
(c) will disappear once processors reach clock frequencies greater than about 10
00MHz.
(d) will disappear once DRAM speeds improve.
Correct answer is

(b)

Your score on this question is:

16.67

Feedback:
See section 5.1.3 of the course notes.
4.
The 200MHz intel-based processor of a computer with no cache is upgraded
to a 500 MHz version of the same processor. On the average, programs now run
(a) at about the same speed.
(b) about 150% faster.
(c) faster on the internet than off it.
(d) about 100% faster (about 1/3 of the memory accesses are instruction fetches)
.
Correct answer is

(a)

Your score on this question is:

0.00

Feedback:
See section 5.1.3 of the course notes.
5.
Which facts about the cache can be determined by calling the following f
unction?
int data[1 << 20];
void callee(int x) {
int i, result;
for (i = 0; i < (1 << 20); i += x) {
result += data[i];
}
}
1. cache line size
2. cache size
3. cache speed

(a) I and II only


(b) I and III only
(c) I only
(d) I, II, and III

Correct answer is

(c)

Your score on this question is:

16.67

Feedback:
See section 5.2.3 of the course notes.
6.
Two computers A and B with a cache in the CPU chip differ only in that A
has an L2 cache and B does not. Which of the following are possible?
1. B executes a program more quickly than A.
2. A executes a program more quickly than B.
3. While executing a program, A fetches more data from main memory than does
B.

(a) I, II and III.


(b) II only.
(c) I and III only.
(d) I and II only.
Correct answer is

(d)

Your score on this question is:

0.00

Feedba
1.
The working set of a program is formed by
(a) the pages that the program is actively using
(b) the memory of the program that is currently in physical memory
(c) all the files the program needs to execute
(d) the libraries required by the program
Correct answer is

(a)

Your score on this question is:

16.67

Feedback:
See section 5.3.3 of the course notes.
2.
Which of the following levels of a typical memory hierarchy transfers da
ta in chunks of smallest size?
(a) CPU registers <--> cache.
(b) main memory <--> disk.
(c) cache <--> main memory.
(d) they all transfer one byte at a time.
Correct answer is

(a)

Your score on this question is:


Feedback:
See section 5.1.3 of the course notes.

16.67

3.
Which of the following is (are) true of the concept of locality of refer
ence?
1. It is used to predict future memory references precisely, with the help of
the compiler.
2. It is a quality of typical programs.
3. It has been mathematically proven.

(a) II only
(b) II and III only
(c) I and II only
(d) I only
Correct answer is

(a)

Your score on this question is:

16.67

Feedback:
See section 5.1.2 of the course notes.
4.
Current technology trends suggest that the need for memory hierarchies
(a) will never disappear.
(b) will disappear once processors reach clock frequencies greater than about 10
00MHz.
(c) will disappear when "broadband" communications start delivering data over th
e internet at speeds greater than 1Mbps.
(d) will disappear once DRAM speeds improve.
Correct answer is

(a)

Your score on this question is:

0.00

Feedback:
See section 5.1.3 of the course notes.
5.
Consider the following fragments from two versions of a program.
Version A
Version B
for (i = 0 ; i < N ; i++ ) {
Read(i);
Calculate(i);
Write(i);
}

for (i = 0 ; i < N ; i++ ) {


Read(i);
}
for (i = 0 ; i < N ; i++ ) {
Calculate(i);
}
for (i = 0 ; i < N ; i++ ) {

Write(i);
}
}
Which of the following are true of version B, compared to version A?
1. B may be faster because of cache effects.
2. B may be slower because of cache effects.
3. B may execute at essentially the same speed as A.

(a) I only
(b) I and III only
(c) II and III only
(d) I, II, and III
Correct answer is

(d)

Your score on this question is:

0.00

Feedback:
See section 5.2.4 of the course notes.
6.
Which facts about the cache can be determined by calling the following f
unction?
int data[1 << 20];
void callee(int x) {
int i, result;
for (i = 0; i < (1 << 20); i += x) {
result += data[i];
}
}
1. cache line size
2. cache size
3. cache speed

(a) I only
(b) I and III only
(c) I, II, and III
(d) I and II only
Correct answer is

(a)

Your score on this question is:

0.00

Feedbac
1.
The working set of a program is formed by
(a) all the files the program needs to execute
(b) the memory of the program that is currently in physical memory
(c) the libraries required by the program
(d) the pages that the program is actively using

Correct answer is

(d)

Your score on this question is:

0.00

Feedback:
See section 5.3.3 of the course notes.
(b) Ideally, the working set of a program is in memory, but this is not alway
s possible.
2.
Which of the following is (are) true of the concept of locality of refer
ence?
1. It is used to predict future memory references precisely, with the help of
the compiler.
2. It is a quality of typical programs.
3. It has been mathematically proven.

(a) I only
(b) I and II only
(c) II and III only
(d) II only
Correct answer is

(d)

Your score on this question is:

0.00

Feedback:
See section 5.1.2 of the course notes.
3.
Which of the following levels of a typical memory hierarchy transfers da
ta in chunks of smallest size?
(a) main memory <--> disk.
(b) cache <--> main memory.
(c) they all transfer one byte at a time.
(d) CPU registers <--> cache.
Correct answer is

(d)

Your score on this question is:

0.00

Feedback:
See section 5.1.3 of the course notes.
4.
A memory hierarchy
(a) makes programs execute more slowly but allows them to be bigger.
(b) limits programs' size but allows them to execute more quickly.
(c) takes advantage of the speed of SRAM and the capacity of disk.
(d) is a way of structuring memory allocation decisions.
Correct answer is

(c)

Your score on this question is:

0.00

Feedback:
See section 5.1.1 of the course notes.
5.
When the following code fragment is executed on a computer with 32-bit i
ntegers and a fully-associative cache with 32-byte cache lines, how many bytes o
f the array a will be fetched into the cache from main memory?
int a[100];
for (i = 0; i < 17; sum += a[i], i++);

(a) exactly 32.


(b) at most 68.
(c) at most 96.
(d) exactly 17.
Correct answer is

(c)

Your score on this question is:

0.00

Feedback:
See section 5.2.1 of the course notes.
6.
When a cache is full and a new cache line needs to be fetched into it, w
hich of the following is a pretty good, practical approach?
(a) denying the memory operation that caused the fetch of the new line.
(b) choosing the cache location currently occupied by the least-recently-used da
ta.
(c) randomly selecting a cache location for the new line.
(d) choosing always the same cache location for the new line.
Correct answer is

(c)

Your score on this question is:

0.00

Feedb
1.
To quickly allocate and free many variables of a commonly used data type
, we could
(a) coalesce blocks when they are freed.
(b) keep a linked list of free objects of that type's size.
(c) minimize the size of the data type.
(d) use sizes which are powers of two.
Correct answer is

(b)

Your score on this question is:

25.00

Feedback:
See section 4.3.2 of the course notes.
2.
Which of the following are advantages of using statistical sampling to p

rofile programs?
1. Exact run times of all functions can be determined.
2. Code can be instrumented automatically.
3. The performance impact due to measurement can be minimal.

(a) II and III only


(b) I and III only
(c) I, II, and III
(d) I and II only
Correct answer is

(a)

Your score on this question is:

25.00

Feedback:
See section 4.1.2 of the course notes.
3.
"Wall time" measures
(a) idle time.
(b) the total duration of a program's execution.
(c) the user time plus the system time.
(d) the time a program spends waiting for input and output.
Correct answer is

(b)

Your score on this question is:

0.00

Feedback:
See section 4.1.1 of the course notes.
4.
Which of the following is likely to offer the best performance improveme
nt for programs that spend 50% of their time comparing strings?
(a) Write in-line code for string comparison to eliminate a procedure ca
ll.
(b) Call a library function for string comparison.
(c) Store strings uniquely so that pointer comparison can be used.
(d) Be sure to use hardware string-comparison instructions.
Correct answer is

(c)

Your score on this question is:

25.00

Feedb
1.
In C and C++, which of the following functions allocate memory from the
heap?
1. printf()
2. creating a new Standard Template Library string
3. cout << "Hello World"

(a) II and III only.


(b) II only.
(c) I only.
(d) I and II only.
Correct answer is

(d)

Your score on this question is:

25.00

Feedback:
See section 4.3.1 of the course notes.
2.
Which of the following are useful for observing program performance?
1. Direct measurement with a stopwatch.
2. Statistical Sampling.
3. System Monitors

(a) I and III only


(b) I, II, and III
(c) I and II only
(d) II and III only
Correct answer is

(b)

Your score on this question is:

25.00

Feedback:
See section 4.1.2 of the course notes.
3.
"CPU time" measures
(a) wall time
(b) the time spent by a program executing program instructions.
(c) the percentage utilization of the CPU by the system.
(d) the time spent executing system functions.
Correct answer is

(b)

Your score on this question is:

25.00

Feedback:
See section 4.1.1 of the course notes.
4.
Which of the following is likely to offer the best performance improveme
nt for programs that spend 50% of their time comparing strings?
(a) Call a library function for string comparison.
(b) Write in-line code for string comparison to eliminate a procedure call.
(c) Be sure to use hardware string-comparison instructions.
(d) Store strings uniquely so that pointer comparison can be used.
Correct answer is

(d)

Your score on this question is:

25.00

Feedba
1.
In C and C++, which of the following functions allocate memory from the
heap?
1. printf()
2. creating a new Standard Template Library string
3. cout << "Hello World"

(a) II and III only.


(b) I and II only.
(c) I only.
(d) II only.
Correct answer is

(b)

Your score on this question is:

25.00

Feedback:
See section 4.3.1 of the course notes.
2.
"CPU time" measures
(a) the time spent by a program executing program instructions.
(b) the time spent executing system functions.
(c) wall time
(d) the percentage utilization of the CPU by the system.
Correct answer is

(a)

Your score on this question is:

25.00

Feedback:
See section 4.1.1 of the course notes.
3.
Which of the following are useful for observing program performance?
1. Direct measurement with a stopwatch.
2. Statistical Sampling.
3. System Monitors

(a) I and II only


(b) II and III only
(c) I, II, and III
(d) I and III only
Correct answer is

(c)

Your score on this question is:


Feedback:

25.00

See section 4.1.2 of the course notes.


4.
Which of the following is likely to offer the best performance improveme
nt for programs that spend 50% of their time comparing strings?
(a) Call a library function for string comparison.
(b) Write in-line code for string comparison to eliminate a procedure call.
(c) Be sure to use hardware string-comparison instructions.
(d) Store strings uniquely so that pointer comparison can be used.
Correct answer is

(d)

Your score on this question is:

25.00

Fee1.
In C and C++, which of the following functions allocate memory from the
heap?
1. printf()
2. creating a new Standard Template Library string
3. cout << "Hello World"

(a) II and III only.


(b) I and II only.
(c) I only.
(d) II only.
Correct answer is

(b)

Your score on this question is:

25.00

Feedback:
See section 4.3.1 of the course notes.
2.
"CPU time" measures
(a) the time spent by a program executing program instructions.
(b) the time spent executing system functions.
(c) wall time
(d) the percentage utilization of the CPU by the system.
Correct answer is

(a)

Your score on this question is:

25.00

Feedback:
See section 4.1.1 of the course notes.
3.
Which of the following are useful for observing program performance?
1. Direct measurement with a stopwatch.
2. Statistical Sampling.
3. System Monitors

(a) I and II only


(b) II and III only
(c) I, II, and III
(d) I and III only
Correct answer is

(c)

Your score on this question is:

25.00

Feedback:
See section 4.1.2 of the course notes.
4.
Which of the following is likely to offer the best performance improveme
nt for programs that spend 50% of their time comparing strings?
(a) Call a library function for string comparison.
(b) Write in-line code for string comparison to eliminate a procedure call.
(c) Be sure to use hardware string-comparison instructions.
(d) Store strings uniquely so that pointer comparison can be used.
Correct answer is

(d)

Your score on this question is:

25.00

Fee
1.
What properties of a variable are specified by the static keyword in C?
1. The variable will be statically allocated.
2. The variable name will be visible only to functions defined within the sam
e file.
3. The variable's value does not change very often. The compiler uses this fa
ct to focus optimizations on other variables.

(a) I only
(b) I and II only.
(c) III only
(d) I and III only.
Correct answer is

(b)

Your score on this question is:

16.67

Feedback:
See section 3.1.1 of the course notes.
2.
Which of the following features apply to standard heap allocation in C?
1. The size of heap objects must be known at compile time.
2. Heap memory must be explicitly allocated.
3. Heap memory is deallocated when a function returns.

(a) I only.
(b) I and III.
(c) I and II only.
(d) II only.
Correct answer is

(d)

Your score on this question is:

0.00

Feedback:
See section 3.1.2 of the course notes.
3.
In this sequence of C statements
long a[10];
ptr = a + 5;
*ptr++ = x;
the last line could be rewritten as
(a) a[6] = x;
(b) ptr = x; *ptr++;
(c) a[5] = x; ptr = ptr + 1;
(d) ptr = ptr + 1; *ptr = x;
Correct answer is

(c)

Your score on this question is:

16.67

Feedback:
See section 3.3.1 of the course notes.
4.
The C expression a->b is equivalent to
(a) (*a).b
(b) (&a).b
(c) (&a) + b
(d) *(a + b)
Correct answer is

(a)

Your score on this question is:

16.67

Feedback:
See section 3.3.1 of the course notes.
5.
In C, calloc() differs from malloc() in that calloc()
(a) is faster.
(b) allocates additional memory from the stack.
(c) detects memory allocation errors.
(d) sets the contents of the block to zero before returning.
Correct answer is

(d)

Your score on this question is:

16.67

Feedback:
See section 3.3.2 of the course notes.
6.
A memory leak is caused by a
(a) function that allocates a large amount of memory from the heap
(b) failure to free allocated memory
(c) bug in the memory allocator that fails to free memory
(d) bug in which too much memory is allocated, causing internal fragmentation
Correct answer is

(b)

Your score on this question is:

16.67

Feedbackv
1.
In C, how are local variables found at run-time?
(a) The variables are always stored at the same address, determined by t
he linker.
(b) The programmer keeps pointers to their location on the heap.
(c) The variables are located at fixed offsets from a frame pointer.
(d) The variables are stored at a fixed offset from the program counter.
Correct answer is

(c)

Your score on this question is:

0.00

Feedback:
See section 3.1.2 of the course notes.
2.
What properties of a variable are specified by the static keyword in C?
1. The variable will be statically allocated.
2. The variable name will be visible only to functions defined within the sam
e file.
3. The variable's value does not change very often. The compiler uses this fa
ct to focus optimizations on other variables.

(a) I and III only.


(b) I only
(c) I and II only.
(d) III only
Correct answer is

(c)

Your score on this question is:

0.00

Feedback:
See section 3.1.1 of the course notes.
3.
To resolve memory leaks in C, one common approach is
(a) to store the source code line whence each block is allocated.

(b) to add padding before and after allocated memory blocks and to fill that mem
ory with a known value.
(c) to ensure that memory blocks are allocated only on word boundaries.
(d) to check whether the number of calls to malloc() is greater than the number
of calls to free().
Correct answer is

(a)

Your score on this question is:

16.67

Feedback:
See section 3.3.6 of the course notes.
4.
What is the value of an uninitialized pointer variable declared within a
function?
(a) its last value from the previous call to the function
(b) 0 (or NULL)
(c) 0xDEADBEEF
(d) the value is undefined
Correct answer is

(d)

Your score on this question is:

16.67

Feedback:
See section 3.3.2 of the course notes.
5.
The unary & operator returns
(a) the logical "and" of two integer operands.
(b) the operand unaltered.
(c) the contents of memory at a given address.
(d) the address of a data object.
Correct answer is

(d)

Your score on this question is:


Feedback:
See section 3.3.1 of the course notes.
6.
In this sequence of C statements
long a[10];
ptr = a + 5;
*ptr++ = x;
the last line could be rewritten as
(a) a[5] = x; ptr = ptr + 1;
(b) ptr = ptr + 1; *ptr = x;
(c) ptr = x; *ptr++;
(d) a[6] = x;
Correct answer is

(a)

16.67

Your score on this question is:

16.67

Feed
1.
In C, how are local variables found at run-time?
(a) The variables are always stored at the same address, determined by t
he linker.
(b) The programmer keeps pointers to their location on the heap.
(c) The variables are located at fixed offsets from a frame pointer.
(d) The variables are stored at a fixed offset from the program counter.
Correct answer is

(c)

Your score on this question is:

0.00

Feedback:
See section 3.1.2 of the course notes.
2.
What properties of a variable are specified by the static keyword in C?
1. The variable will be statically allocated.
2. The variable name will be visible only to functions defined within the sam
e file.
3. The variable's value does not change very often. The compiler uses this fa
ct to focus optimizations on other variables.

(a) I and III only.


(b) I only
(c) I and II only.
(d) III only
Correct answer is

(c)

Your score on this question is:

0.00

Feedback:
See section 3.1.1 of the course notes.
3.
To resolve memory leaks in C, one common approach is
(a) to store the source code line whence each block is allocated.
(b) to add padding before and after allocated memory blocks and to fill that mem
ory with a known value.
(c) to ensure that memory blocks are allocated only on word boundaries.
(d) to check whether the number of calls to malloc() is greater than the number
of calls to free().
Correct answer is

(a)

Your score on this question is:


Feedback:
See section 3.3.6 of the course notes.

16.67

4.
What is the value of an uninitialized pointer variable declared within a
function?
(a) its last value from the previous call to the function
(b) 0 (or NULL)
(c) 0xDEADBEEF
(d) the value is undefined
Correct answer is

(d)

Your score on this question is:

16.67

Feedback:
See section 3.3.2 of the course notes.
5.
The unary & operator returns
(a) the logical "and" of two integer operands.
(b) the operand unaltered.
(c) the contents of memory at a given address.
(d) the address of a data object.
Correct answer is

(d)

Your score on this question is:

16.67

Feedback:
See section 3.3.1 of the course notes.
6.
In this sequence of C statements
long a[10];
ptr = a + 5;
*ptr++ = x;
the last line could be rewritten as
(a) a[5] = x; ptr = ptr + 1;
(b) ptr = ptr + 1; *ptr = x;
(c) ptr = x; *ptr++;
(d) a[6] = x;
Correct answer is

(a)

Your score on this question is:

16.67

Fee
1.
In C, local variables allocated inside functions are allocated
(a) in the heap
(b) in static storage
(c) on the stack
(d) in a fifo
Correct answer is

(c)

Your score on this question is:

16.67

Feedback:
See section 3.1.2 of the course notes.
2.
Which of the following are true about statically allocated data in C pro
grams?
1. Its location is chosen by the compiler.
2. Its location may change during execution if more memory is required.
3. Its location is not known directly but can be found in a static symbol tab
le.

(a) II and III only.


(b) I only.
(c) III only.
(d) I and II only.
Correct answer is

(b)

Your score on this question is:

16.67

Feedback:
See section 3.1.1 of the course notes.
3.
In C, which of the following is the best way to detect when a pointer is
freed twice?
(a) Modify free() to set the freed data to zero.
(b) Flag all blocks as free or not, and check the flag when calling free().
(c) Keep a log of addresses that have been freed and scan the log before calling
free().
(d) Set pointers to NULL after freeing them.
Correct answer is

(b)

Your score on this question is:

0.00

Feedback:
See section 3.3.6 of the course notes.
4.
A garbage collector
(a) frees all memory blocks that will not be accessed in the future.
(b) removes old versions of local variables from the stack .
(c) frees memory blocks marked as "deleteable".
(d) frees memory blocks that cannot be reached by dereferencing pointers.
Correct answer is

(d)

Your score on this question is:


Feedback:
See section 3.3.7 of the course notes.

0.00

5.
Consider the following fragment of C code.
int *p = (int *) calloc(100);
int *q = p;
free(p);
Immediately after executing it, which of the following are true about p and q?
1. p and q are identical pointers to freed storage.
2. p points to freed storage, and q points to an allocated block of size 100.
3. p should not be free()d again, but invoking free(q) is all right.

(a) III only


(b) II only
(c) II and III only
(d) I only
Correct answer is

(d)

Your score on this question is:

16.67

Feedback:
See section 3.3.4 of the course notes.
6.
A memory leak is caused by a
(a) bug in the memory allocator that fails to free memory
(b) bug in which too much memory is allocated, causing internal fragmentation
(c) failure to free allocated memory
(d) function that allocates a large amount of memory from the heap
Correct answer is

(c)

Your score on this question is:

16.67

Fee
1.
In C, how is the length of a character string determined?
(a) The length is stored in the first byte of the string.
(b) The length is stored in the first 4 bytes; the string characters follow this
.
(c) The length is predetermined by the compiler.
(d) The length is the number of characters preceding a zero.
Correct answer is

(d)

Your score on this question is:

14.29

Feedback:
See section 2.4.1 of the course notes.
2.
Given the address of a C struct at runtime, how is the address of a memb

er element in the struct determined?


(a) A constant offset associated with the member is added to the address
.
(b) The struct consists of an array of pointers to the elements of the struct.
(c) A linear search is made from the base address of the struct.
(d) The element name is looked up in a symbol table.
Correct answer is

(a)

Your score on this question is:

14.29

Feedback:
See section 2.4.2 of the course notes.
3.
Assume that array a is at location 1000 (decimal). Execution of the foll
owing program results in what being printed?
int a[12];
main() {
int i;
for (i = 0; i < 12; i++) a[i] = i;
printf("%d\n", *(a + 5));
}

(a) 5
(b) 1020
(c) 1005
(d) 20
Correct answer is

(a)

Your score on this question is:

14.29

Feedback:
See section 2.4.1 of the course notes.
4.
What happens in a C program when an addition would cause integer overflo
w?
(a) An exception-handler is called with the two operands as parameters.
(b) The correct value is coerced to a floating point number.
(c) Execution is terminated.
(d) An incorrect result is produced and execution continues.
Correct answer is

(d)

Your score on this question is:

0.00

Feedback:
See section 2.2.2 of the course notes.
5.
Which of the following numerical operations is most likely to lead to lo
ss of precision?

(a) Integer addition


(b) Integer multiplication
(c) Floating-point addition
(d) Floating-point multiplication
Correct answer is

(c)

Your score on this question is:

14.29

Feedback:
See section 2.3.2 of the course notes.
6.
In C, what is the following binary number in hexadecimal?
11010101
(a) 0xD5
(b) 0xB5
(c) 0xAB
(d) 0x5D
Correct answer is

(a)

Your score on this question is:

14.29

Feedback:
See section 2.1.2 of the course notes.
7.
What is the value of the following C expression?
0x1234 & 0x5432

(a) 0x5636
(b) 0x6666
(c) 0x1030
(d) 0x1111
Correct answer is

(c)

Your score on this question is:

14.29

Feed
1.
Given the address of a C struct at runtime, how is the address of a memb
er element in the struct determined?
(a) A constant offset associated with the member is added to the address
.
(b) The element name is looked up in a symbol table.
(c) The struct consists of an array of pointers to the elements of the struct.
(d) A linear search is made from the base address of the struct.
Correct answer is

(a)

Your score on this question is:

14.29

Feedback:
See section 2.4.2 of the course notes.
2.
Assume that array a is at location 1000 (decimal). Execution of the foll
owing program results in what being printed?
int a[12];
main() {
int i;
for (i = 0; i < 12; i++) a[i] = i;
printf("%d\n", *(a + 5));
}

(a) 5
(b) 20
(c) 1005
(d) 1020
Correct answer is

(a)

Your score on this question is:

14.29

Feedback:
See section 2.4.1 of the course notes.
3.
Given the following declaration and initialization of s, what is the val
ue of the expression s[6]?
char s[] = "string";

(a) an unpredictable value


(b) '\n'
(c) 'g'
(d) '\0'
Correct answer is

(d)

Your score on this question is:

14.29

Feedback:
See section 2.4.1 of the course notes.
4.
How is -10 (decimal) represented in an 8-bit 2's complement binary forma
t?
(a) 11110110
(b) 10001010
(c) 11110101
(d) 11111010
Correct answer is

(a)

Your score on this question is:

14.29

Feedback:
See section 2.2.1 of the course notes.
5.
In C, using default floating point settings, what happens when a floatin
g-point computation results in an overflow?
(a) Program execution is halted.
(b) An exception is raised unless disabled by calling _controlfp().
(c) A special value "infinity" is computed, testable with _finite().
(d) An erroneous value is computed and execution continues.
Correct answer is

(c)

Your score on this question is:

14.29

Feedback:
See section 2.3.3 of the course notes.
6.
What is the value of the following C expression?
0x1234 << 3

(a) 0x48CE
(b) 0x9340
(c) 0x1234000
(d) 0x91A0
Correct answer is

(d)

Your score on this question is:

14.29

Feedback:
See section 2.1.3 of the course notes.
7.
In C, what is the following binary number in hexadecimal?
11010101
(a) 0xB5
(b) 0x5D
(c) 0xAB
(d) 0xD5
Correct answer is

(d)

Your score on this question is:

14.29

Feed
1.
In C, assuming that an int takes 4 bytes, if array a is declared as foll
ows and a has the value 0x10000, what is the value of the expression a + 2?

int a[12];

(a) 0x10002
(b) 0x10008
(c) 0x10004
(d) 8 plus the contents of location 0x10000
Correct answer is

(b)

Your score on this question is:

14.29

Feedback:
See section 2.4.1 of the course notes.
2.
How many bytes are allocated by the following C declaration and initiali
zation?
char s[] = "quiz";

(a) 4
(b) 20
(c) 16
(d) 5
Correct answer is

(d)

Your score on this question is:

14.29

Feedback:
See section 2.4.1 of the course notes.
3.
Given the address of a C struct at runtime, how is the address of a memb
er element in the struct determined?
(a) The element name is looked up in a symbol table.
(b) A constant offset associated with the member is added to the address.
(c) The struct consists of an array of pointers to the elements of the struct.
(d) A linear search is made from the base address of the struct.
Correct answer is

(b)

Your score on this question is:

14.29

Feedback:
See section 2.4.2 of the course notes.
4.
How is 46 (decimal) represented in an 8-bit 2's complement binary format
?
(a) 00101100
(b) 00101110
(c) 00011110
(d) 01000110

Correct answer is

(b)

Your score on this question is:

14.29

Feedback:
See section 2.2.1 of the course notes.
5.
In C, using default floating point settings, what happens when a floatin
g-point computation results in an overflow?
(a) An exception is raised unless disabled by calling _controlfp().
(b) Program execution is halted.
(c) A special value "infinity" is computed, testable with _finite().
(d) An erroneous value is computed and execution continues.
Correct answer is

(c)

Your score on this question is:

14.29

Feedback:
See section 2.3.3 of the course notes.
6.
Which of the following explains why it is convenient to use hexadecimal
notation when programming?
(a) Memory is accessed in 4-bit chunks.
(b) Hexadecimal can represent larger numbers than decimal.
(c) Not all computer numbers can be written in decimal form.
(d) Hexadecimal digits line up with bit and byte boundaries.
Correct answer is

(d)

Your score on this question is:

0.00

Feedback:
See section 2.1.2 of the course notes.
7.
What is the value of the following C expression?
0x1234 | 0x5432

(a) 0x4606
(b) 0x1030
(c) 0x5434
(d) 0x5636
Correct answer is

(d)

Your score on this question is:

14.29

Feedbac
1.
Compared to a sequence of machine code instructions, a fragment of C cod

e
(a) does not engage any transistors during its execution
(b) may describe the same algorithm
(c) describes the actions of the computer, not just of the CPU
(d) is the native way to program most computers
Correct answer is

(b)

Your score on this question is:

0.00

Feedback:
See section 1.1.2 of the course notes.
2.
Which of the following Visual C++ objects are contained within a "Projec
t"?
1. Files
2. Visual C++ Solutions
3. Flow charts

(a) II and III only


(b) II only
(c) I only
(d) I, II and III
Correct answer is

(c)

Your score on this question is:

7.14

Feedback:
See section 1.1.4 of the course notes.
3.
Which of the following must be true if a program is stopped at a specifi
c line within the Visual C++ debugger?
1. There is at least one breakpoint enabled.
2. There is a breakpoint enabled on that line.
3. There is a breakpoint enabled on the line preceding that line.

(a) I only
(b) I and II only
(c) I and III only
(d) none
Correct answer is

(d)

Your score on this question is:

7.14

Feedback:
See section 1.2.2 of the course notes.
4.
When debugging using Visual C++, which of the following are possible thr

ough the Watch window?


1. The program's execution can be stopped.
2. The value of an arbitrary C expression can be calculated.
3. The value of a program variable can be set.

(a) II only
(b) II and III only
(c) III only
(d) I, II, and III.
Correct answer is

(b)

Your score on this question is:

7.14

Feedback:
See section 1.2.3 of the course notes.
5.
At which of the following times is an activation record created?
1. When a program starts executing.
2. Every time a function is invoked.
3. When a variable is declared.

(a) II only
(b) I and II only
(c) II and III only
(d) III only
Correct answer is

(b)

Your score on this question is:

7.14

Feedback:
See section 1.4.2 of the course notes.
(b) The program starts executing by calling the function main().
6.
What is printed as a result of execution of the following program?
#include <stdio.h>
void callee(int * count) {
(*count)++;
}
int main (int argc, char *argv[]) {
int count = 4;
callee(&count);
printf("%d", count);
return 0;
}

(a) 8
(b) 4

(c) 5
(d) It cannot be determined from the information given.
Correct answer is

(c)

Your score on this question is:

7.14

Feedback:
See section 1.4.1 of the course notes.
7.
Consider the function factorial() defined as follows.
int factorial(int n) {
if (n == 1) return n;
return n * factorial(n - 1);
}
How many activation records of factorial are allocated by invocation of the expr
ession factorial(4)?
(a) 5
(b) 1
(c) 0
(d) 4
Correct answer is

(d)

Your score on this question is:

7.14

Feedback:
See section 1.4.2 of the course notes.
8.
Consider the following program segment.
int factorial(int * arg) {
int n = *arg;
if (n == 1) return n;
return n * factorial(n - 1);
}
When the segment is executed, the variable n is allocated to
(a) many addresses that were chosen by the compiler
(b) just one address, and it is not known to the compiler
(c) many addresses none of which is known to the compiler
(d) just one address, and it was chosen by the compiler
Correct answer is

(c)

Your score on this question is:

7.14

Feedback:
See section 1.4.1 of the course notes.
9.
In a computer in which both addresses and integers are 32 bits wide, how
many bytes of memory will the compiler allocate for following code fragment?

int a;
int * b = &a;

(a) 8
(b) 32
(c) 0
(d) 4
Correct answer is

(a)

Your score on this question is:

7.14

Feedback:
See section 1.3.2 of the course notes.
10.
The Visual C++ Memory window displays
(a) the names and values of variables in memory, interpreted as 32-bit i
ntegers no matter what the variables' types
(b) the contents of memory, interpreted in one of several ways, without the asso
ciated variable names
(c) the contents of memory, interpreted as 32-bit integers, without the associat
ed variable names
(d) the names and values of variables in memory, interpreted in one of several w
ays
Correct answer is

(b)

Your score on this question is:

0.00

Feedback:
See section 1.3.3 of the course notes.
11.
Programs compiled for an Intel Pentium processor do not execute properly
on a SPARC processor from Sun Microsystems because
(a) copyrights regarding code cannot be violated
(b) the operation codes understood by the two processors are different
(c) the assembly mnemonics for the same "opcode" are different in the two proces
sors
(d) the memory of a SPARC CPU is numbered from top to bottom
Correct answer is

(b)

Your score on this question is:

0.00

Feedback:
See section 1.5.1 of the course notes.
(c) The assembly mnemonics can be different and yet assemble into the same op
codes
12.
The program counter contains
(a) the number of CPU instructions a program has executed so far
(b) the amount of memory a program is currently using

(c) the address of the CPU instruction that is about to be executed


(d) the number of times a program has been executed
Correct answer is

(c)

Your score on this question is:

7.14

Feedback:
See section 1.5.2 of the course notes.
13.
A jump instruction
(a) increases the program counter
(b) changes the program counter only if its operand is equal to zero
(c) unconditionally sets the program counter to its operand
(d) changes a pointer to point to the next element of an array
Correct answer is

(c)

Your score on this question is:

7.14

Feedback:
See section 1.5.2 of the course notes.
14.
Which of the following are true of the effect that optimizations have on
the machine code generated by compilers?
1. The resulting code will be faster and/or smaller.
2. The resulting code will be clearer.
3. The resulting code will be harder to debug.

(a) I and III only


(b) I and II only
(c) I only
(d) I, II, and III
Correct answer is

(a)

Your score on this question is:

7.14

Feedba
.
Which of the following is able to describe a computation at the highest
level of abstraction?
(a) logic Gates
(b) machine code
(c) C++ code
(d) C code
Correct answer is

(c)

Your score on this question is:


Feedback:

7.14

See section 1.1.2 of the course notes.


2.
Integrated programming environments make it difficult to mix and match t
ools from different sources. This is
(a) good, because it ensures compilation is not done incrementally by ac
cident
(b) good, because tools from different sources cannot be made to interact with e
ach other
(c) bad, because no single vendor is likely to be the source of all the best too
ls
(d) bad, because all the tools will then have the same user interface
Correct answer is

(c)

Your score on this question is:

0.00

Feedback:
See section 1.1.4 of the course notes.
3.
Which of the following must be true if a program is stopped at a specifi
c line within the Visual C++ debugger?
1. There is at least one breakpoint enabled.
2. There is a breakpoint enabled on that line.
3. There is a breakpoint enabled on the line preceding that line.

(a) I only
(b) none
(c) I and III only
(d) I and II only
Correct answer is

(b)

Your score on this question is:

0.00

Feedback:
See section 1.2.2 of the course notes.
4.
When using a debugger to find the cause of a program's incorrect behavio
r,
(a) the faulty code fragment must first be identified
(b) it is fastest to start by stopping the debugger long before the behavior app
ears
(c) the program is usually executed to the point at which the behavior occurs an
d then executed backwards to find the cause
(d) it is often necessary to start the program multiple times under the debugger
Correct answer is

(d)

Your score on this question is:


Feedback:
See section 1.2.4 of the course notes.

7.14

5.
What does the following program print?
void callee(int * count) {
(*count)++;
}
int main (int argc, char *argv[]) {
int count = 4;
callee(count);
printf("%d", count);
return 0;
}

(a) nothing: it will not compile successfully


(b) 4
(c) 5
(d) 8
Correct answer is

(a)

Your score on this question is:

7.14

Feedback:
See section 1.4.1 of the course notes.
6.
Consider the following program.
int i;
int j = 1;
int callee(int number) {
int plusone;
plusone = number + 1;
return plusone;
}
int main (int argc, char *argv[]) {
if (j == 1) return callee(i);
return j;
}
Which of the following are allocated in the activation record immediately after
the function callee() is invoked?
(a) i only.
(b) plusone and number only.
(c) i, j and number only.
(d) plusone only.
Correct answer is

(b)

Your score on this question is:


Feedback:
See section 1.4.2 of the course notes.
7.
Consider the following program.

0.00

int square(int * arg) {


int n = * arg;
return n * n;
}
int main (int argc, char * argv[]) {
int arg = strtol(argv[1], NULL, 0);
return square(arg);
}
When it is executed with the argument 5, the variable n is allocated to
(a) many addresses neither of which are known to the compiler.
(b) many addresses chosen by the compiler.
(c) exactly one address not known to the compiler.
(d) exactly one address chosen by the compiler.
Correct answer is

(c)

Your score on this question is:

7.14

Feedback:
See section 1.4.1 of the course notes.
8.
Consider the following function.
int factorial(int n) {
if (n == 1) return n;
return n * factorial(n - 1);
}
How many activation records are "popped" when it is invoked by the expression fa
ctorial(4)?
(a) 4
(b) 5
(c) 1
(d) 0
Correct answer is

(a)

Your score on this question is:

7.14

Feedback:
See section 1.4.2 of the course notes.
9.
In one computer, the bytes with addresses A, A+1, A+2 and A+3 contain th
e integer 256, and the variable declared with int * a; has the value A. In a dif
ferent computer, the bytes with addresses B, B+1, B+2 and B+3 also contain the i
nteger 256, and the variable declared with int * b has the value B. Which of the
following are necessarily true?
1. The contents of A+1 are equal to the contents of B+1.
2. The contents of A+1 are equal to the contents of B+2.
3. *a == *b

(a) I and III only


(b) III only
(c) II and III only
(d) I only
Correct answer is

(b)

Your score on this question is:

0.00

Feedback:
See section 1.3.3 of the course notes.
10.
Consider the following segment of C source code.
int a = 8;
int b = *&a;
What is the value of variable b at the end of execution of the segment?
(a) (int) &a
(b) &a
(c) (int) &b
(d) a
Correct answer is

(d)

Your score on this question is:

7.14

Feedback:
See section 1.3.2 of the course notes.
11.
Which of the following is a good reason (are good reasons) to equip the
CPU with small amounts of fast memory?
1. To make the design of the compiler simpler
2. To make some CPU instructions smaller
3. To make some CPU instructions faster

(a) I, II, and III


(b) III only
(c) II and III only
(d) II only
Correct answer is

(c)

Your score on this question is:

7.14

Feedback:
See section 1.5.3 of the course notes.
12.
Which of the following are true of the effect that optimizations have on
the machine code generated by compilers?
1. The resulting code will be faster and/or smaller.
2. The resulting code will be clearer.

3. The resulting code will be harder to debug.

(a) I and II only


(b) I only
(c) I, II, and III
(d) I and III only
Correct answer is

(d)

Your score on this question is:

0.00

Feedback:
See section 1.5.3 of the course notes.
13.
How many return addresses does a C function have as a program executes?
(a) one
(b) as many as the number of times it is invoked
(c) as many as the number of return statements within the function
(d) two, one for each branch
Correct answer is

(b)

Your score on this question is:

0.00

Feedback:
See section 1.5.2 of the course notes.
14.
Suppose that, using a tool such as the memory window of Visual C++, we f
ound that a certain set of contiguous memory locations contained the integer 0xC
605CD623A8365000000. What could these memory locations hold?
1. the integer 0xC605CD623A8365000000
2. a string
3. a CPU instruction

(a) I and II only


(b) I, II, and III
(c) III only
(d) I only
Correct answer is

(b)

Your score on this question is:

7.14

Feedbac
1.
Which of the following does a debugger do?
1. Analyze the source code to find programming errors.
2. Decode machine code generated by a compiler.
3. Stop execution of a program.

(a) I, II, and III.


(b) III only
(c) I and III only
(d) II and III only
Correct answer is

(d)

Your score on this question is:

0.00

Feedback:
See section 1.1.3 of the course notes.
2.
Which of the following is able to describe a computation at the highest
level of abstraction?
(a) logic Gates
(b) machine code
(c) C code
(d) C++ code
Correct answer is

(d)

Your score on this question is:

7.14

Feedback:
See section 1.1.2 of the course notes.
3.
When debugging using Visual C++, which of the following are possible thr
ough the Watch window?
1. The program's execution can be stopped.
2. The value of an arbitrary C expression can be calculated.
3. The value of a program variable can be set.

(a) II and III only


(b) III only
(c) I, II, and III.
(d) II only
Correct answer is

(a)

Your score on this question is:

7.14

Feedback:
See section 1.2.3 of the course notes.
4.
When using a debugger to find the cause of a program's incorrect behavio
r,
(a) the program is usually executed to the point at which the behavior o
ccurs and then executed backwards to find the cause
(b) the faulty code fragment must first be identified
(c) it is fastest to start by stopping the debugger long before the behavior app

ears
(d) it is often necessary to start the program multiple times under the debugger
Correct answer is

(d)

Your score on this question is:

0.00

Feedback:
See section 1.2.4 of the course notes.
5.
What does the following program print?
void callee(int * count) {
(*count)++;
}
int main (int argc, char *argv[]) {
int count = 4;
callee(count);
printf("%d", count);
return 0;
}

(a) 4
(b) nothing: it will not compile successfully
(c) 8
(d) 5
Correct answer is

(b)

Your score on this question is:

7.14

Feedback:
See section 1.4.1 of the course notes.
6.
What does the following program print?
int callee(int * count) {
count++;
return *count;
}
int main (int argc, char *argv[]) {
int count = 4;
int retval;
retval = callee(&count);
printf("%d", retval);
return 0;
}

(a) cannot be determined from the information given.


(b) 5
(c) 8
(d) 4
Correct answer is

(a)

Your score on this question is:

7.14

Feedback:
See section 1.4.1 of the course notes.
7.
Consider the following function.
int factorial(int n) {
if (n == 1) return n;
return n * factorial(n - 1);
}
How many activation records are "popped" when it is invoked by the expression fa
ctorial(4)?
(a) 0
(b) 4
(c) 1
(d) 5
Correct answer is

(b)

Your score on this question is:

7.14

Feedback:
See section 1.4.2 of the course notes.
8.
What is printed as a result of execution of the following program?
#include <stdio.h>
void callee(int * count) {
(*count)++;
}
int main (int argc, char *argv[]) {
int count = 4;
callee(&count);
printf("%d", count);
return 0;
}

(a) It cannot be determined from the information given.


(b) 4
(c) 5
(d) 8
Correct answer is

(c)

Your score on this question is:

7.14

Feedback:
See section 1.4.1 of the course notes.
9.
Consider the following segment of a C program.

int i = 99;
int a[100];
i = a[i + 1];
Which of the following is true of the segment?
(a) Execution will fail because a has the wrong size.
(b) i will have the value 99 at the end of any execution of the segment.
(c) When executed, the program will be prematurely terminated by the operating s
ystem because of an illegal memory access.
(d) i will have the value of the last element of the array a at the end of any e
xecution of the segment.
Correct answer is

(b)

Your score on this question is:

0.00

Feedback:
See section 1.3.5 of the course notes.
10.
Consider the following code.
char a[100];
a[99] = *((char *) (((int) &a[0]) + 4))
If integers are 32 bits wide, which of the following values is equal to a[99]?
(a) the integer stored in the bytes a[4], a[5], a[6] and a[7]
(b) a[3]
(c) a[4]
(d) a[0] + 4
Correct answer is

(c)

Your score on this question is:

0.00

Feedback:
See section 1.3.5 of the course notes.
11.
Which of the following is a good reason (are good reasons) to equip the
CPU with small amounts of fast memory?
1. To make the design of the compiler simpler
2. To make some CPU instructions smaller
3. To make some CPU instructions faster

(a) II only
(b) I, II, and III
(c) III only
(d) II and III only
Correct answer is

(d)

Your score on this question is:


Feedback:

0.00

See section 1.5.3 of the course notes.


12.
Suppose that, using a tool such as the memory window of Visual C++, we f
ound that a certain set of contiguous memory locations contained the integer 0xC
605CD623A8365000000. What could these memory locations hold?
1. the integer 0xC605CD623A8365000000
2. a string
3. a CPU instruction

(a) III only


(b) I only
(c) I and II only
(d) I, II, and III
Correct answer is

(d)

Your score on this question is:

0.00

Feedback:
See section 1.5.1 of the course notes.
13.
The program counter contains
(a) the number of CPU instructions a program has executed so far
(b) the number of times a program has been executed
(c) the address of the CPU instruction that is about to be executed
(d) the amount of memory a program is currently using
Correct answer is

(c)

Your score on this question is:

7.14

Feedback:
See section 1.5.2 of the course notes.
14.
A CPU register is a word of CPU memory that
(a) houses a critical variable for the duration of the execution of a pr
ogram
(b) is explicitly loaded and unloaded from normal memory by compiler-generated i
nstructions
(c) records the results of periodic CPU diagnostics
(d) is automatically loaded when a CPU instruction refers to a word of normal me
mory
Correct answer is

(b)

Your score on this question is:


Feedb
View Assessment Result
Family Name:

Chen

7.14

Given Name:
Fang
Login: nwpu043760
E-mail:
chenfangyi73@126.com
Status:
Enrolled
Assessment Name:
Instance:
4

Multiple-Choice Quiz 4

Section:
NWPU-SSD5-6
During:
Fall 2006
Section Status:
Active
For course:
(SSD5)

Data Structures and Algorithms

Corresponding to:
SSD5
At:
Software College of Northwestern Polytechnical University
Your performance was as follows:
You took 3 minutes on this assessment from Sat Nov 11 2006 15:43:25 GMT+
0800 to Sat Nov 11 2006 15:45:35 GMT+0800.
Total score: 80.00

1.
Which of the following statements regarding the design of the Standard Template
Library (STL) in C++ is (are) true?
1. Each STL algorithm is usable with one specific container.
2. The STL does not use templates and instead relies on polymorphism.

(a) II only
(b) I only
(c) I and II
(d) None
Correct answer is

(d)

Your score on this question is:

0.00

Feedback:
See section 2.1.1, subsection "The Standard Template Library," in the course not
es.
2.
Access to ranges of elements in an STL container is typically handled by

(a) references
(b) iterators
(c) suitable access member functions
(d) pointers
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 2.1.3 of the course notes.
3.
In the STL, common algorithms are instantiated for multiple types of container c
lasses by using _____ to provide a uniform interface between the algorithms and
containers.
(a) arrays
(b) pointers
(c) iterators
(d) virtual functions
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 2.1.1, subsection "Iterators," in the course notes.
4.
A typical implementation of a deque in the C++ STL minimizes the need to copy el
ements upon the frontal insertion of new items by
(a) reserving memory at the front of the deque's stored elements
(b) inserting the element at the next available position in the deque and mainta
ining a table of element positions
(c) inserting the element at the end of the deque and maintaining a table of ele
ment positions
(d) using a background thread to reallocate memory when necessary
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 2.2.3, subsection "Implementation," in the course notes.
5.

In the C++ Standard Template Library, vectors and deques differ in their interfa
ces for handling which of the following operations?
1. Insertion of an element at the front of the container
2. Insertion of an element at the end of the container
3. Removal of an element from the front of the container

(a) I and II only


(b) III only
(c) I only
(d) I and III only
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See Section 2.2.3, subsection "Interface," in the course notes.
6.
Consider the following C++ program fragment.
vector<int> A(10);
A.push_back( 5000 );
At the end of an execution of this fragment, the size of vector A is
(a) 10
(b) 11
(c) dependent on machine and compiler
(d) 5000
Correct answer is

(b)

Your score on this question is:

0.00

Feedback:
See section 2.2.2 of the course notes.
7.
Consider the execution of the following.
vector<int> A(10,20);
Which of the following accurately describes what is created?
(a) An array of 20 arrays of ints, each of size 10

(b) An array of 10 ints, each initialized to 20


(c) An array of ints, indexed from 10 to 20
(d) An array of 10 arrays of ints, each of size 20
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 2.1.2 of the course notes.
8.
The size of an STL vector is defined to be the
(a) maximum number of elements that can be stored in the vector without
resizing
(b) number of bytes the vector occupies in memory
(c) total of the sizes of the data members in the vector class
(d) number of elements currently stored in the vector
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 2.1.2 of the course notes.
9.
Which of the following statements is (are) true regarding C-style strings?
1. They are terminated by the null character.
2. Storing a five-character string requires at least seven characters.

(a) I and II
(b) II only
(c) None
(d) I only
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 2.1, subsection "C-style Strings," in the course notes.
10.
Which of the following statements is (are) true regarding strings in C++?
1. Strings in C++ are supported by the standard class string.
2. A constructor for the class string can accept a C-style string as an argum
ent.

(a) I only
(b) II only
(c) I and II
(d) None
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 2.1, subsection "C-style Strings," in the course notes.
Go to top of assessment.
Total score: 80.00
? Copyright 2004 iCarnegie, Inc. All rights reserved.
View Assessment Result
Family Name:
Chen
Given Name:
Fang
Login: nwpu043760
E-mail:
chenfangyi73@126.com
Status:
Enrolled
Assessment Name:
Instance:
3

Multiple-Choice Quiz 4

Section:
NWPU-SSD5-6
During:
Fall 2006
Section Status:
Active
For course:
(SSD5)

Data Structures and Algorithms

Corresponding to:
SSD5
At:
Software College of Northwestern Polytechnical University
Your performance was as follows:
You took 10 minutes on this assessment from Sat Nov 11 2006 15:33:04 GMT
+0800 to Sat Nov 11 2006 15:42:13 GMT+0800.
Total score: 80.00

1.

For an STL iterator it, execution of the statement


it--;
does which of the following?
(a) Decreases by 1 the size of the container pointed to by it.
(b) Post-decrements the item to which the iterator points.
(c) Steps the iterator backwards to the previous item.
(d) Pre-decrements the item to which the iterator points.
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 2.1.3 of the course notes.
2.
For an STL iterator it, execution of the statement
++it;
does which of the following?
(a) Post-increments the item to which the iterator points.
(b) Pre-increments the item to which the iterator points.
(c) Increase by 1 the size of the container pointed to by it.
(d) Advances the iterator to the next item.
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 2.1.3 of the course notes.
3.
In the STL, common algorithms are instantiated for multiple types of container c
lasses by using _____ to provide a uniform interface between the algorithms and
containers.
(a) pointers
(b) iterators
(c) virtual functions
(d) arrays
Correct answer is

(b)

Your score on this question is:


Feedback:

10.00

See section 2.1.1, subsection "Iterators," in the course notes.


4.
The class vector in the C++ STL contains which of the following methods?
1. push_back
2. push_front
3. pop_front

(a) I and II only


(b) I, II, and III
(c) I only
(d) II and III only
Correct answer is

(c)

Your score on this question is:

0.00

Feedback:
See section 2.2.3, subsection "Interface," in the course notes.
5.
Which of the following statements is (are) true of typical implementations of ve
ctors and deques?
1.
uses
2.
ns at

A vector's implementation uses one array, whereas a deque's implementation


multiple arrays.
Insertions at the front of a deque tend to be more efficient than insertio
the front of a vector.

(a) II only
(b) I and II
(c) I only
(d) None
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 2.2.3, subsection "Implementation," in the course notes.
6.
The size of an STL vector is defined to be the

(a) number of bytes the vector occupies in memory


(b) total of the sizes of the data members in the vector class
(c) number of elements currently stored in the vector
(d) maximum number of elements that can be stored in the vector without resizing
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 2.1.2 of the course notes.
7.
Consider the following declaration that makes use of a user-defined class Thing.
vector<Thing> A(10);
In order that it compile, the class Thing must have which of the following?
(a) an assignment operator
(b) a copy constructor
(c) a destructor
(d) a default constructor
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 2.1.2 of the course notes.
8.
In STL vectors, _____ refers to the maximum number of items that can be stored w
ithout resizing, and _____ refers to the number of items stored.
(a) range, domain
(b) size, capacity
(c) domain, range
(d) capacity, size
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 2.1.2 of the course notes.
9.
A C-style string is stored as an array of characters that ends with _____ charac
ter.

(a) a '\n'
(b) any white-space
(c) a '\0'
(d) a '0'
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See Chapter 2, page 74, in the course textbook.
10.
Consider the following C++ program segment, assuming that string is a class.
string str1("Hello, World");
str1[5] = 'Z';
The overloaded operator[] function invoked in the above program segment should h
ave which of the following return types?
(a) char
(b) char *
(c) char &
(d) const char &
Correct answer is

(c)

Your score on this question is:

0.00

Feedback:
See Chapter 2, pages 79C81, in the course textbook.
Go to top of assessment.
Total score: 80.00
? Copyright 2004 iCarnegie, Inc. All rights reserved.
View Assessment Result
Family Name:
Chen
Given Name:
Fang
Login: nwpu043760
E-mail:
chenfangyi73@126.com
Status:
Enrolled
Assessment Name:
Instance:
2

Multiple-Choice Quiz 4

Section:
NWPU-SSD5-6
During:
Fall 2006
Section Status:
Active
For course:
(SSD5)

Data Structures and Algorithms

Corresponding to:
SSD5
At:
Software College of Northwestern Polytechnical University
Your performance was as follows:
You took 3 minutes on this assessment from Sat Nov 11 2006 15:26:01 GMT+
0800 to Sat Nov 11 2006 15:28:57 GMT+0800.
Total score: 80.00

1.
Which of the following statements regarding the design of the Standard Template
Library (STL) in C++ is (are) true?
1. Each STL algorithm is usable with one specific container.
2. The STL does not use templates and instead relies on polymorphism.

(a) None
(b) I and II
(c) II only
(d) I only
Correct answer is

(a)

Your score on this question is:

0.00

Feedback:
See section 2.1.1, subsection "The Standard Template Library," in the course not
es.
2.
The main abstractions of the Standard Template Library include which of the foll
owing?
1. Iterators
2. Exception handlers
3. Algorithms

(a) I and II only


(b) I and III only
(c) I only
(d) III only
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 2.1.1, subsection "STL Overview," in the course notes.
3.
For an STL iterator it, execution of the statement
it--;
does which of the following?
(a) Steps the iterator backwards to the previous item.
(b) Decreases by 1 the size of the container pointed to by it.
(c) Pre-decrements the item to which the iterator points.
(d) Post-decrements the item to which the iterator points.
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 2.1.3 of the course notes.
4.
A typical implementation of a deque in the C++ STL minimizes the need to copy el
ements upon the frontal insertion of new items by
(a) reserving memory at the front of the deque's stored elements
(b) inserting the element at the end of the deque and maintaining a table of ele
ment positions
(c) inserting the element at the next available position in the deque and mainta
ining a table of element positions
(d) using a background thread to reallocate memory when necessary
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 2.2.3, subsection "Implementation," in the course notes.

5.
The STL deque container contains which of the following methods?
1. push_back
2. push_front
3. pop_front

(a) I only
(b) III only
(c) II and III only
(d) I, II, and III
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 2.2.3, subsection "Interface," in the course notes.
6.
Consider the following C++ program fragment.
vector<int> A(10);
A.push_back( 5000 );
At the end of an execution of this fragment, the size of vector A is
(a) 5000
(b) 10
(c) dependent on machine and compiler
(d) 11
Correct answer is

(d)

Your score on this question is:

0.00

Feedback:
See section 2.2.2 of the course notes.
7.
The capacity of an STL vector is defined to be the
(a) maximum number of elements the vector could possibly have on the giv
en machine
(b) number of elements currently stored in the vector
(c) difference between the current number of elements and the maximum number of
elements
(d) maximum number of elements that can be stored in the vector without resizing

Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 2.1.2 of the course notes.
8.
Consider the following program segment.
vector<int> A(10);
A.resize(0);
A.push_back(5000);
At the end of an execution of this fragment, the size of vector A is
(a) 10
(b) 1
(c) 5000
(d) 0
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 2.1.2 of the course notes.
9.
A C-style string is stored as an array of characters that ends with _____ charac
ter.
(a) a '0'
(b) a '\0'
(c) any white-space
(d) a '\n'
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See Chapter 2, page 74, in the course textbook.
10.
Which of the following statements is (are) true regarding C-style strings?
1. They are terminated by the null character.

2. Storing a five-character string requires at least seven characters.

(a) I and II
(b) II only
(c) I only
(d) None
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 2.1, subsection "C-style Strings," in the course notes.
Go to top of assessment.
Total score: 80.00
? Copyright 2004 iCarnegie, Inc. All rights reserved.
View Assessment Result
Family Name:
Chen
Given Name:
Fang
Login: nwpu043760
E-mail:
chenfangyi73@126.com
Status:
Enrolled
Assessment Name:
Instance:
1

Multiple-Choice Quiz 4

Section:
NWPU-SSD5-6
During:
Fall 2006
Section Status:
Active
For course:
(SSD5)

Data Structures and Algorithms

Corresponding to:
SSD5
At:
Software College of Northwestern Polytechnical University
Your performance was as follows:
You took 9 minutes on this assessment from Sat Nov 11 2006 15:15:22 GMT+
0800 to Sat Nov 11 2006 15:23:48 GMT+0800.
Total score: 50.00

1.

For an STL iterator it, execution of the statement


it--;
does which of the following?
(a) Decreases by 1 the size of the container pointed to by it.
(b) Post-decrements the item to which the iterator points.
(c) Pre-decrements the item to which the iterator points.
(d) Steps the iterator backwards to the previous item.
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 2.1.3 of the course notes.
2.
Access to ranges of elements in an STL container is typically handled by
(a) pointers
(b) suitable access member functions
(c) iterators
(d) references
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 2.1.3 of the course notes.
3.
Execution of which of the following statements sets an STL iterator it s
o that it points to the first element of a container A?
(a) begin( A, it );
(b) A.reset( it );
(c) A.begin( it );
(d) it = A.begin();
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 2.1.3 of the course notes.
4.
A typical implementation of a deque in the C++ STL minimizes the need to copy el
ements upon the frontal insertion of new items by
(a) reserving memory at the front of the deque's stored elements

(b) inserting the element at the next available position in the deque and mainta
ining a table of element positions
(c) using a background thread to reallocate memory when necessary
(d) inserting the element at the end of the deque and maintaining a table of ele
ment positions
Correct answer is

(a)

Your score on this question is:

0.00

Feedback:
See section 2.2.3, subsection "Implementation," in the course notes.
5.
In the C++ Standard Template Library, vectors and deques differ in their interfa
ces for handling which of the following operations?
1. Insertion of an element at the front of the container
2. Insertion of an element at the end of the container
3. Removal of an element from the front of the container

(a) I only
(b) III only
(c) I and II only
(d) I and III only
Correct answer is

(d)

Your score on this question is:

0.00

Feedback:
See Section 2.2.3, subsection "Interface," in the course notes.
6.
Consider the execution of the following.
vector<int> A(10,20);
Which of the following accurately describes what is created?
(a) An array of ints, indexed from 10 to 20
(b) An array of 10 arrays of ints, each of size 20
(c) An array of 10 ints, each initialized to 20
(d) An array of 20 arrays of ints, each of size 10
Correct answer is

(c)

Your score on this question is:

0.00

Feedback:
See section 2.1.2 of the course notes.
7.
If A is an STL vector, then the effect of executing the statement
A[i] = x;
is to
(a) create an iterator x pointing to position i in the array
(b) check array bounds, enlarge the vector if necessary, and then write x to pos
ition i
(c) write x to position i of the vector, without bounds checking
(d) check array bounds, and write x to position i if and only if i is in the pro
per range
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 2.1.2 of the course notes.
8.
In STL vectors, _____ refers to the maximum number of items that can be stored w
ithout resizing, and _____ refers to the number of items stored.
(a) size, capacity
(b) capacity, size
(c) range, domain
(d) domain, range
Correct answer is

(b)

Your score on this question is:

0.00

Feedback:
See section 2.1.2 of the course notes.
9.
Which of the following statements is (are) true regarding C-style strings?
1. They are terminated by the null character.
2. Storing a five-character string requires at least seven characters.

(a) I only
(b) II only

(c) I and II
(d) None
Correct answer is

(a)

Your score on this question is:

0.00

Feedback:
See section 2.1, subsection "C-style Strings," in the course notes.
10.
A C-style string is stored as an array of characters that ends with _____ charac
ter.
(a) a '0'
(b) any white-space
(c) a '\0'
(d) a '\n'
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See Chapter 2, page 74, in the course textbook.
Go to top of assessment.
Total score: 50.00
? Copyright 2004 iCarnegie, Inc. All rights reserved.
View Assessment Result: Multiple-Choice Quiz 7

Your performance was as follows:


1.
Consider the following statement using the STL sort() routine.
sort( A.begin(), A.end(), f );
Which of the following most accurately describes the result of executing this st
atement?

(a) Container A is sorted using the function f for assignments.


(b) Container A is sorted by applying function f to its elements.
(c) Container A is sorted using sorting algorithm f.
(d) Container A is sorted using the Boolean valued function f for comparisons.
Correct answer is (d)
Your score on this question is: 10.00
Feedback:
See section 4.1.3 of the course notes.
-------------------------------------------------------------------------------2.
Consider the following C++ template function.
template <class T>
void mystery_sort(vector<T>& v) {
for (int i = 0; i < v.size() - 1; i++) {
int best = i;
for (int j = i + 1; j < v.size(); j++) {
if (v[j] < v[best]) {
best = j;
}
}
if (best != i) {
T temp = v[i];
v[i] = v[best];
v[best] = temp;
}
}
}
The above function implements which of the following sort algorithms?

(a) Selection sort


(b) Quicksort
(c) Bubble sort
(d) Merge sort
Correct answer is (a)
Your score on this question is: 0.00
Feedback:
See section 4.1.2, subsection "Selection Sort," in the course notes.

-------------------------------------------------------------------------------3.
In a search over a data set with 1000 items, the maximum number of items examin

ed by a linear search is _____, and the maximum number of items examined by a bi


nary search is _____.

(a) 100, 3
(b) 10, 1000
(c) 3, 100
(d) 1000, 10
Correct answer is (d)
Your score on this question is: 10.00
Feedback:
See section 4.1.1 in the course notes.

-------------------------------------------------------------------------------4.
Which of the following search algorithms can be applied to unsorted data?
Linear search
Binary search

(a) I only
(b) II only
(c) None
(d) I and II
Correct answer is (a)
Your score on this question is: 0.00
Feedback:
See section 4.1.1 in the course notes.

-------------------------------------------------------------------------------5.
In the context of hashing, what is meant by a collision?
(a) The insertion algorithm cannot find an empty slot in the table.
(b) Two key/value pairs have the same value.
(c) Two different keys hash to the same slot.
(d) The hash function returns a value larger than the table size.
Correct answer is (c)
Your score on this question is: 10.00

Feedback:
See section 4.1.3 of the course notes.
-------------------------------------------------------------------------------6.
A hash table that stores whether or not a key is present, but does not associat
e any other information with the key, is commonly known as

(a) an associative hash table


(b) a hash map
(c) a hash set
(d) a hash function
Correct answer is (c)
Your score on this question is: 0.00
Feedback:
See section 4.1.3 of the course notes.
-------------------------------------------------------------------------------7.
Consider the following C++ code fragment.
for( int i = 0; i < n; i += 2 ) {
for( int j = 0; j < n; j += 3 ) {
for( int k = 0; k < n; k += 4 ) {
body;
}
}
}
If body executes in constant time, then the asymptotic running time that most cl
osely bounds from above the performance of this code fragment is

(a) O(n log n)


(b) O(n)
(c) O(n2)
(d) O(n3)
Correct answer is (d)
Your score on this question is: 0.00
Feedback:
See section 4.2.1 of the course notes.
-------------------------------------------------------------------------------8.
Consider the following C++ code fragment.

for( int i = 0; i < n; i += 2 ) {


for(int j = i; j > 0; j -= 3 ) {
body
}
}
If body executes in constant time, then the asymptotic running time that most cl
osely bounds from above the performance of this code fragment is

(a) O(n2)
(b) O(n3)
(c) O(n log n)
(d) O(n)
Correct answer is (a)
Your score on this question is: 0.00
Feedback:
See section 4.2.1 of the course notes.
-------------------------------------------------------------------------------9.
The asymptotic running time of merge sort with an input array of length n is mo
st closely bound from above by?
(a) O(n log n)
(b) O(n)
(c) O(2n)
(d) O(n2)
Correct answer is (a)
Your score on this question is: 10.00
Feedback:
See section 4.2.1 of the course notes.
-------------------------------------------------------------------------------10.
Consider the following definition of a recursive function, power, that will per
form exponentiation.
int power( int b, int e )
{
if( e == 0 ) return 1;
if( e % 2 = 0 ) return power( b * b, e/2 );
return b * power( b * b, e/2 );
}
Asymptotically in terms of the exponent e, the number of calls to power that occ
ur as a result of the call power(b,e) is

(a) linear
(b) quadratic
(c) exponential
(d) logarithmic
Correct answer is (d)
===================================
Consider the following C++ template function.
template <class T>
void mystery_sort(vector<T>& v) {
for (int i = 0; i < v.size() - 1; i++) {
int best = i;
for (int j = i + 1; j < v.size(); j++) {
if (v[j] < v[best]) {
best = j;
}
}
if (best != i) {
T temp = v[i];
v[i] = v[best];
v[best] = temp;
}
}
}
The above function implements which of the following sort algorithms?

(a) Selection sort


(b) Merge sort
(c) Bubble sort
(d) Quicksort
Correct answer is (a)
Your score on this question is: 10.00
Feedback:
See section 4.1.2, subsection "Selection Sort," in the course notes.

-------------------------------------------------------------------------------2.
Which of the following statements is true of the selection-sort algorithm?
It is a divide-and-conquer algorithm typically implemented using recursion.
An implementation of the algorithm typically requires the use of a hash table.

(a) I and II
(b) II only
(c) I only
(d) None
Correct answer is (d)
Your score on this question is: 0.00
Feedback:
See section 4.1.2, subsection "Selection Sort," in the course notes.

-------------------------------------------------------------------------------3.
Which of the following statements about both arrays and linked lists is (are) t
rue?
Direct element access using subscripts is supported in both the containers.
Both can be searched using binary search.

(a) I, II, and III


(b) II only
(c) III only
(d) II and III only
Correct answer is (c)
Your score on this question is: 10.00
Feedback:
See section 4.1.1 of the course notes.
-------------------------------------------------------------------------------4.
Which of the following search algorithms can be applied to unsorted data?
Linear search
Binary search

(a) I and II
(b) None
(c) II only
(d) I only
Correct answer is (d)
Your score on this question is: 10.00

Feedback:
See section 4.1.1 in the course notes.

-------------------------------------------------------------------------------5.
In the context of hashing, what is meant by a collision?
(a) The insertion algorithm cannot find an empty slot in the table.
(b) Two key/value pairs have the same value.
(c) Two different keys hash to the same slot.
(d) The hash function returns a value larger than the table size.
Correct answer is (c)
Your score on this question is: 10.00
Feedback:
See section 4.1.3 of the course notes.
-------------------------------------------------------------------------------6.
Which of the following indicates the primary difficulty with hashing in general
?
(a) Hash functions are hard to compute.
(b) Hash tables take up a lot of memory.
(c) Collisions will occur.
(d) Access in hash tables is slow.
Correct answer is (c)
Your score on this question is: 10.00
Feedback:
See section 4.1.3 of the course notes.
-------------------------------------------------------------------------------7.
Consider the following C++ code fragment.
for( int i = 0; i < n; i++ ) {
for( int j = 0; j < n; j++ ) {
for( int k = 0; k < n; k++ ) {
body;
}
}
}
If body executes in constant time, then the asymptotic running time that most cl

osely bounds from above the performance of this code fragment is

(a) O(2n)
(b) O(n2)
(c) O(n3)
(d) O(n)
Correct answer is (c)
Your score on this question is: 10.00
Feedback:
See section 4.2.1 of the course notes.
-------------------------------------------------------------------------------8.
Consider the following definition of a recursive function, power, that will per
form exponentiation.
int power( int b, int e )
{
if( e == 0 ) return 1;
if( e % 2 = 0 ) return power( b * b, e/2 );
return b * power( b * b, e/2 );
}
Asymptotically in terms of the exponent e, the number of calls to power that occ
ur as a result of the call power(b,e) is

(a) logarithmic
(b) exponential
(c) linear
(d) quadratic
Correct answer is (a)
Your score on this question is: 10.00
Feedback:
See section 4.2.1 of the course notes.
-------------------------------------------------------------------------------9.
Consider the following C++ code fragment.
for( int i = 0; i < n; i++ ) {
for( int j = 0; j < n/5; j++ ) {
body;
}
}
If body executes in constant time, then the asymptotic running time that most cl

osely bounds from above the performance of this code fragment is

(a) O(n)
(b) O(n3)
(c) O(n log n)
(d) O(n2)
Correct answer is (d)
Your score on this question is: 10.00
Feedback:
See section 4.2.1 of the course notes.
-------------------------------------------------------------------------------10.
Consider the following C++ code fragment.
for( int i = 1; i < n; i *= 2 ) body;
If body executes in O(1) time, then the asymptotic running time that most closel
y bounds the code fragment above is

(a) O(log n)
(b) O(n)
(c) O(n2)
(d) O(n log n)
Correct answer is (a)
Your score on this question is: 0.00
Feedback:
See section 4.2.1 of the course notes.
--------------------------------------------------------------------------View Assessment Result: Multiple-Choice Quiz 7

Your performance was as follows:


1.
Consider the following C++ template function.
template <class T>
void mystery_sort(vector<T>& v) {
for (int i = 0; i < v.size() - 1; i++) {
int best = i;
for (int j = i + 1; j < v.size(); j++) {

if (v[j] < v[best]) {


best = j;
}
}
if (best != i) {
T temp = v[i];
v[i] = v[best];
v[best] = temp;
}
}
}
The above function implements which of the following sort algorithms?

(a) Merge sort


(b) Selection sort
(c) Bubble sort
(d) Quicksort
Correct answer is (b)
Your score on this question is: 10.00
Feedback:
See section 4.1.2, subsection "Selection Sort," in the course notes.

-------------------------------------------------------------------------------2.
Which of the following statements about arrays and linked lists is (are) true i
n the context of a sorting algorithm?
The sorting algorithm is asymptotically faster if the elements are in an array r
ather than a linked list.
For the algorithm to be implemented, direct element access must be supported in
both the containers.

(a) None
(b) I only
(c) I and II
(d) II only
Correct answer is (a)
Your score on this question is: 0.00
Feedback:
See section 4.1.2 of the course notes.
-------------------------------------------------------------------------------3.

Which of the following statements about both arrays and linked lists is (are) t
rue?
Direct element access using subscripts is supported in both the containers.
Both can be searched using binary search.
Elements of both the containers can be sorted.

(a) III only


(b) II and III only
(c) I, II, and III
(d) II only
Correct answer is (a)
Your score on this question is: 10.00
Feedback:
See section 4.1.1 of the course notes.
-------------------------------------------------------------------------------4.
Consider a data set of 100 items. Which of the following is a search algorithm
(are search algorithms) that could possibly examine 25 items in this set before
succeeding?
Linear search
Binary search

(a) II only
(b) None
(c) I and II
(d) I only
Correct answer is (d)
Your score on this question is: 0.00
Feedback:
See section 4.1.1 in the course notes.

-------------------------------------------------------------------------------5.
For a template hash table class to work with some user-defined key type Thing,
the user has to specify
(a) just the size of the table, templates take care of the rest.
(b) the type Thing, a hash function for Thing, and equality testing for Thing.
(c) just the type Thing.
(d) the type Thing and a hash function for Thing.

Correct answer is (b)


Your score on this question is: 0.00
Feedback:
See section 4.1.4 of the course notes.
-------------------------------------------------------------------------------6.
Which of the following is true about a good hash function?
(a) It should only output prime numbers.
(b) It should produce small outputs for small inputs.
(c) It should never output a prime number.
(d) It should produce apparently random values for given items.
Correct answer is (d)
Your score on this question is: 0.00
Feedback:
See section 4.1.3 of the course notes.
-------------------------------------------------------------------------------7.
Searching for an element in a linked list containing n elements is most closely
bounded from above by

(a) O(1)
(b) O(n3)
(c) O(n)
(d) O(n2)
Correct answer is (c)
Your score on this question is: 0.00
Feedback:
See section 4.2.1 of the course notes.
-------------------------------------------------------------------------------8.
Consider the following C++ code fragment.
for( int i = 0; i < n; i += 2 ) {
for(int j = i; j > 0; j -= 3 ) {
body
}
}

If body executes in constant time, then the asymptotic running time that most cl
osely bounds from above the performance of this code fragment is

(a) O(n log n)


(b) O(n2)
(c) O(n)
(d) O(n3)
Correct answer is (b)
Your score on this question is: 10.00
Feedback:
See section 4.2.1 of the course notes.
-------------------------------------------------------------------------------9.
Consider the following code fragment.
for( int i = n; i > 0; i /= 2 ) body;
If body executes in O(1) time, then the asymptotic running time that most closel
y bounds the fragment is

(a) O(n)
(b) O(log n)
(c) O(n2)
(d) O(n log n)
Correct answer is (b)
Your score on this question is: 10.00
Feedback:
See section 4.2.1 of the course notes.
-------------------------------------------------------------------------------10.
Consider the following definition of a recursive function, power, that will per
form exponentiation.
int power( int b, int e )
{
if( e == 0 ) return 1;
if( e % 2 = 0 ) return power( b * b, e/2 );
return b * power( b * b, e/2 );
}
Asymptotically in terms of the exponent e, the number of calls to power that occ
ur as a result of the call power(b,e) is

(a) exponential
(b) logarithmic
(c) linear
(d) quadratic
Correct answer is (b)
Your score on this question is: 0.00
Feedback:
See section 4.2.1 of the course notes.
-------------------------------------------------------------------------------Go to top of assessment.
Total score: 40.00
? Copyright 2004 iCarnegie, Inc. All rights reserved.
View Assessment Result: Multiple-Choice Quiz 7

Your performance was as follows:


1.
Which of the following statements about arrays and linked lists is (are) true i
n the context of a sorting algorithm?
The sorting algorithm is asymptotically faster if the elements are in an array r
ather than a linked list.
For the algorithm to be implemented, direct element access must be supported in
both the containers.

(a) I only
(b) I and II
(c) None
(d) II only
Correct answer is (c)
Your score on this question is: 10.00
Feedback:
See section 4.1.2 of the course notes.
-------------------------------------------------------------------------------2.
Consider the following C++ template function.

template <class T>


void mystery_sort(vector<T>& v) {
for (int i = 0; i < v.size() - 1; i++) {
int best = i;
for (int j = i + 1; j < v.size(); j++) {
if (v[j] < v[best]) {
best = j;
}
}
if (best != i) {
T temp = v[i];
v[i] = v[best];
v[best] = temp;
}
}
}
The above function implements which of the following sort algorithms?

(a) Bubble sort


(b) Quicksort
(c) Merge sort
(d) Selection sort
Correct answer is (d)
Your score on this question is: 10.00
Feedback:
See section 4.1.2, subsection "Selection Sort," in the course notes.

-------------------------------------------------------------------------------3.
In a search over a data set with 1000 items, the maximum number of items examin
ed by a linear search is _____, and the maximum number of items examined by a bi
nary search is _____.

(a) 100, 3
(b) 10, 1000
(c) 1000, 10
(d) 3, 100
Correct answer is (c)
Your score on this question is: 10.00
Feedback:
See section 4.1.1 in the course notes.

-------------------------------------------------------------------------------4.
Which of the following search algorithms can be applied to unsorted data?
Linear search
Binary search

(a) None
(b) I only
(c) I and II
(d) II only
Correct answer is (b)
Your score on this question is: 10.00
Feedback:
See section 4.1.1 in the course notes.

-------------------------------------------------------------------------------5.
Which of the following is true about a good hash function?
(a) It should produce small outputs for small inputs.
(b) It should never output a prime number.
(c) It should produce apparently random values for given items.
(d) It should only output prime numbers.
Correct answer is (c)
Your score on this question is: 10.00
Feedback:
See section 4.1.3 of the course notes.
-------------------------------------------------------------------------------6.
A hash table that stores whether or not a key is present, but does not associat
e any other information with the key, is commonly known as

(a) a hash function


(b) a hash map
(c) a hash set
(d) an associative hash table
Correct answer is (c)

Your score on this question is: 10.00


Feedback:
See section 4.1.3 of the course notes.
-------------------------------------------------------------------------------7.
Consider the following C++ code fragment.
for( int i = 1; i < n; i *= 2 ) body;
If body executes in O(1) time, then the asymptotic running time that most closel
y bounds the code fragment above is

(a) O(n)
(b) O(n log n)
(c) O(log n)
(d) O(n2)
Correct answer is (c)
Your score on this question is: 10.00
Feedback:
See section 4.2.1 of the course notes.
-------------------------------------------------------------------------------8.
The asymptotic running time that most closely bounds the performance of inserti
on sort on an input array with length n is
(a) O(n2)
(b) O(n)
(c) O(2n)
(d) O(n log n)
Correct answer is (a)
Your score on this question is: 0.00
Feedback:
See section 1.7.2 of the course notes.
-------------------------------------------------------------------------------9.
Consider the following recursive definition of a function f in C++.
int f(int n) {
if( n == 0 ) {
return 1;

}
else {
return f(n / 2);
}
}
The asymptotic running time of the call f(n) is most closely bound from above by

(a) O(n)
(b) O(n log n)
(c) O(log n)
(d) O(n2)
Correct answer is (c)
Your score on this question is: 10.00
Feedback:
See section 4.2.1 of the course notes.
-------------------------------------------------------------------------------10.
Consider the following C++ code fragment.
for( int i = 0; i < n; i++ ) {
for( int j = 0; j < n/5; j++ ) {
body;
}
}
If body executes in constant time, then the asymptotic running time that most cl
osely bounds from above the performance of this code fragment is

(a) O(n log n)


(b) O(n3)
(c) O(n2)
(d) O(n)
Correct answer is (c)
Your score on this question is: 10.00
Feedback:
See section 4.2.1 of the course notes.
-------------------------------------------------------------------------------Go to top of assessment.
Total score: 90.00
? Copyright 2004 iCarnegie, Inc. All rights reserved.

10.
Consider the following C++ function that uses a divide and conquer approach to
calculate the sum of a range of numbers.
int sum(int i, int j) {
if (i == j) {
return i;
}
else {
int mid = (i+j) / 2;
int result = sum(i,mid) + sum(mid+1,j);
return result;
}
}
Which of the following lines of code from the above function divides this proble
m into sub-problems?

(a) int mid = (i+j) / 2;


(b) return result;
(c) if (i == j) {
(d) int result = sum(i,mid) + sum(mid+1,j);
Correct answer is (d)
Your score on this question is: 10.00
The STL is heavily based on
(a) templates
(b) polymorphism
(c) inheritance
(d) object oriented programming
Correct answer is (a)
Your score on this question is: 10.00
Feedback:
See section 2.1.1 of the course notes.

-------------------------------------------------------------------------------2.
Which of the following statements regarding the design of the Standard Template
Library (STL) in C++ is (are) true?
Each STL algorithm is usable with one specific container.
The STL does not use templates and instead relies on polymorphism.

(a) None

(b) I only
(c) II only
(d) I and II
Correct answer is (a)
Your score on this question is: 10.00
Feedback:
See section 2.1.1, subsection "The Standard Template Library," in the course not
es.

-------------------------------------------------------------------------------3.
The main abstractions of the Standard Template Library include which of the fol
lowing?
Iterators
Exception handlers
Algorithms

(a) I only
(b) III only
(c) I and III only
(d) I and II only
Correct answer is (c)
Your score on this question is: 10.00
Feedback:
See section 2.1.1, subsection "STL Overview," in the course notes.

-------------------------------------------------------------------------------4.
In the C++ Standard Template Library, vectors and deques differ in their interf
aces for handling which of the following operations?
Insertion of an element at the front of the container
Insertion of an element at the end of the container
Removal of an element from the front of the container

(a) I and III only


(b) I and II only
(c) III only
(d) I only
Correct answer is (a)

Your score on this question is: 10.00


Feedback:
See Section 2.2.3, subsection "Interface," in the course notes.

-------------------------------------------------------------------------------5.
The class vector in the C++ STL contains which of the following methods?
push_back
push_front
pop_front

(a) I, II, and III


(b) I and II only
(c) II and III only
(d) I only
Correct answer is (d)
Your score on this question is: 10.00
Feedback:
See section 2.2.3, subsection "Interface," in the course notes.

-------------------------------------------------------------------------------6.
Consider the following C++ program fragment.
vector<int> A(10);
A.push_back( 5000 );
At the end of an execution of this fragment, the size of vector A is

(a) 5000
(b) 10
(c) 11
(d) dependent on machine and compiler
Correct answer is (c)
Your score on this question is: 0.00
Feedback:
See section 2.2.2 of the course notes.

-------------------------------------------------------------------------------7.
Consider the following declaration that makes use of a user-defined class Thing
.
vector<Thing> A(10);
In order that it compile, the class Thing must have which of the following?

(a) a copy constructor


(b) a default constructor
(c) a destructor
(d) an assignment operator
Correct answer is (b)
Your score on this question is: 10.00
Feedback:
See section 2.1.2 of the course notes.
-------------------------------------------------------------------------------8.
The size of an STL vector is defined to be the
(a) number of bytes the vector occupies in memory
(b) total of the sizes of the data members in the vector class
(c) number of elements currently stored in the vector
(d) maximum number of elements that can be stored in the vector without resizin
g
Correct answer is (c)
Your score on this question is: 10.00
Feedback:
See section 2.1.2 of the course notes.
-------------------------------------------------------------------------------9.
Consider the following C++ program segment, assuming that string is a class.
string str1("Hello, World");
str1[5] = 'Z';
The overloaded operator[] function invoked in the above program segment should h
ave which of the following return types?

(a) char
(b) const char &
(c) char *

(d) char &


Correct answer is (d)
Your score on this question is: 10.00
Feedback:
See Chapter 2, pages 79C81, in the course textbook.

-------------------------------------------------------------------------------10.
Consider the following C++ program fragment, which is a partial declaration of
the class string.
class string {
public:
string(const char* cstring = "");
bool operator== (const string & rhs);
...
};
Given this class and two string objects called s1 and s2, which of the following
is not a legal statement?

(a) bool ans = (s2 == "hello");


(b) bool ans = ("hello" == s1);
(c) string s3("Hello, World");
(d) bool ans = (s1 == s2);
Correct answer is (b)
Your score on this question is: 10.00
Feedback:
See Chapter 2, pages 76C77, in the course textbook.

10.
The asymptotic running time that most closely bounds the performance of a selec
tion sort on an input array with length n is
(a) O(2n)
(b) O(n log n)
(c) O(n2)
(d) O(n)
Correct answer is (c)
Your score on this question is: 0.00
1.

Consider the following outline of a template sorting function.


template<class T> void sort( T a[], int n ) { ... }
For a given sorting algorithm S, which of the following is true about using this
outline to implement S?

(a) It is a poor choice since it does not work with linked lists.
(b) It is a reasonable way to implement S.
(c) It is a poor choice since templates slow down sorting.
(d) It is impossible since the algorithm cannot know how to compare two instanc
es of type T.
Correct answer is (b)
Your score on this question is: 10.00
1.
Which of the following statements properly allocates an array of 100 int
egers?
(a) int *A = new int[100];
(b) int &A = new int[100];
(c) int *A = new (int) 100;
(d) int A = new int[100];
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 1.3.1 of the course notes.
2.
A programmer can detect a syntax error in a C++ program when the program is
(a) compiled
(b) linked
(c) executed
(d) loaded
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 1.1.2, subsection "Phases of C++ Program Development," in the course
notes.
3.
Which of the following lists of C++ types are ordered increasingly by si

ze, as computed by sizeof()?


(a) long, int, char, short
(b) short, char, int, long
(c) char, short, int, long
(d) long, int, short, char
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 1.3.1 of the course notes.
4.
Lines at a store, file cabinets, and bookcases are real-world entities that most
resemble _____ in computer science.
(a) object-oriented programming languages
(b) functional programming languages
(c) algorithms
(d) data structures
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 1.2.1, subsection "Data Structures," in the course notes.
5.
Which of the following is not a predefined stream object in C++?
(a) cin
(b) cfile
(c) cout
(d) cerr
Correct answer is

(b)

Your score on this question is:


Feedback:

10.00

See Appendix A.4, page A-9, in the course notes.


6.

In C++, the standard input stream is accessible using the object _____, and the
standard output stream is accessible using the object _____.
(a) cin, cout
(b) stdin, stdout
(c) input, output
(d) keyboard, screen
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 1.3.3, subsection "Using the Standard Streams," in the course notes.
7.
In C++, a preprocessor directive is a
(a) command-line argument supplied to the linker
(b) comment that prevents the linking of object files into executable programs
(c) comment ignored by the preprocessor
(d) single-line command introduced into a C++ source file
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 1.3.4, subsection "Text Substitution," in the course notes.
8.
In C++, the directive #include is processed by the
(a) preprocessor
(b) compiler
(c) Standard Template Library
(d) linker
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 1.1.2, subsection "Phases of C++ Program Development," in the course
notes.

9.
Which of the following is true about a class without a (user-defined) co
nstructor?
(a) It must have a destructor.
(b) It cannot have an assignment operator.
(c) It cannot have a destructor.
(d) It may have a destructor, but might not.
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 1.3.2 of the course notes.
10.
Assume that Thing is a user-defined class, and consider the following function.
Thing f(Thing& A) {
Thing B;
B.x = A.x;
return B;
}
Where in this code will a copy constructor be used?
(a) In passing the parameter
(b) In the creation of the local variable B
(c) In copying the data from A to B
(d) In the return operation
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 1.3.2 of the course notes.

1.
Which of the following statements properly allocates an array of 100 int
egers?
(a) int &A = new int[100];
(b) int *A = new (int) 100;
(c) int A = new int[100];
(d) int *A = new int[100];
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 1.3.1 of the course notes.
2.
Which of the following statements about C++ is (are) true
1. It is strongly typed.
2. It has been standardized by ISO.

(a) None
(b) II only
(c) I and II
(d) I only
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 1.1.1 in the course notes.
3.
What is the type name used to represent extra precision real numbers in
C++?
(a) float
(b) long float
(c) real
(d) double
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 1.3.1 of the course notes.
4.
Decomposition of a problem involves which of the following?
(a) Identifying entities and relationships that will aid in solving the
problem
(b) Reverse-engineering an algorithm that solves a different problem
(c) Determining a programming language for implementing a solution to the proble
m
(d) Simplifying the problem by eliminating low-priority requirements
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 1.2.2, subsection "Decomposing the Representation," in the course no
tes.
5.
In C++, the standard input stream is accessible using the object _____, and the
standard output stream is accessible using the object _____.
(a) keyboard, screen
(b) cin, cout
(c) input, output
(d) stdin, stdout
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 1.3.3, subsection "Using the Standard Streams," in the course notes.
6.
Regarding C++ standard I/O, the _____ operator writes to a stream and the _____
operator reads from a stream.
(a) >>, <<
(b) >, <
(c) <, >
(d) <<, >>
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 1.3.3, subsection "Using the Standard Streams," in the course notes.
7.
In C++, the preprocessor is
(a) a virtual CPU that can be used to simulate machine-code execution
(b) a tool that manipulates source files before compilation

(c) a debugging tool common to most visual programming environments


(d) a set of APIs provided by several compiler vendors
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 1.3.4, subsection "Text Substitution," in the course notes.
8.
In C++, the directive #include is processed by the
(a) compiler
(b) Standard Template Library
(c) linker
(d) preprocessor
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 1.1.2, subsection "Phases of C++ Program Development," in the course
notes.
9.
The purpose of a constructor is to
(a) handle assignments between instances of the class
(b) clean up memory when an instance goes out of scope
(c) prevent memory leaks
(d) initialize data members of a class properly after space has been allocated
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 1.3.2 of the course notes.
10.
The purpose of the assignment operator is to
(a) prevent memory leaks
(b) be used internally in an object's copy constructor
(c) initialize data members when an instance is first created
(d) provide for proper assignment between objects
Correct answer is

(d)

Your score on this question is:

10.00

Feedback
1.
Which of the following statements properly allocates an array of 100 int
egers?
(a) int *A = new (int) 100;
(b) int *A = new int[100];
(c) int A = new int[100];
(d) int &A = new int[100];
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 1.3.1 of the course notes.
2.
At the end of the _____ stage for a C++ program, a(n) _____ can be produced.
(a) preprocessing, object file
(b) linking, executable image
(c) compiling, preprocessed file
(d) linking, source file
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 1.1.2, subsection " Phases of C++ Program Development," in the cours
e notes.
3.
Each of the following is a basic C++ type except
(a) byte
(b) bool
(c) unsigned int
(d) char
Correct answer is

(a)

Your score on this question is:


Feedback:
See section 1.3.1 of the course notes.
4.

10.00

Which of the following statements might be produced by the decomposition of a pr


oblem into objects and relationships?
1. "A is a type of B"
2. "A B contains a C"

(a) I only
(b) None
(c) II only
(d) I and II
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 1.2.2, subsection "Decomposing the Representation," in the course no
tes.
5.
Regarding C++ standard I/O, the _____ operator writes to a stream and the _____
operator reads from a stream.
(a) <<, >>
(b) <, >
(c) >>, <<
(d) >, <
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 1.3.3, subsection "Using the Standard Streams," in the course notes.
6.
To read data from a file into a C++ program using class ifstream, it is necessar
y to include the _____ library header file.
(a) fstream
(b) string
(c) ctype
(d) iomanip
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See Appendix A.4, page A-13, in the course notes.
7.
Consider the following C++ program segment.
#include <iostream>
#include <cstdlib>
using namespace std;
int main(int argc, char* argv[]) {
return EXIT_SUCCESS;
}
The first two lines of this program segment typically direct the preprocessor to
(a) compile two methods and prepare them for use by the program segment'
s source code
(b) define two macros available for use in the program segment
(c) include the contents of two files into the program segment's source code
(d) define two keywords to aid in debugging the program segment
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 1.1.2, subsection " Phases of C++ Program Development," in the cours
e notes.
8.
In C++, the directive #include is processed by the
(a) linker
(b) compiler
(c) Standard Template Library
(d) preprocessor
Correct answer is

(d)

Your score on this question is:


Feedback:

10.00

See section 1.1.2, subsection "Phases of C++ Program Development," in the course
notes.
9.
The purpose of a constructor is to
(a) initialize data members of a class properly after space has been all
ocated
(b) handle assignments between instances of the class
(c) prevent memory leaks
(d) clean up memory when an instance goes out of scope
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 1.3.2 of the course notes.
10.
Assume that Thing is a user-defined class, and consider the following function.
Thing f(Thing& A) {
Thing B;
B.x = A.x;
return B;
}
Where in this code will a copy constructor be used?
(a) In the creation of the local variable B
(b) In copying the data from A to B
(c) In passing the parameter
(d) In the return operation
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
An ordered set of directives that can be carried out mechanically is known as a(
n)
(a) hash table
(b) algorithm
(c) associative array
(d) tree
1.
Which of the following statements properly allocates an array of 100 int
egers?
(a) int A = new int[100];
(b) int *A = new (int) 100;

(c) int *A = new int[100];


(d) int &A = new int[100];
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 1.3.1 of the course notes.
2.
Valid comments in C++ include which of the following?
1. /* comment */
2. / comment
3. // comment

(a) I and III only


(b) I and II only
(c) II and III only
(d) I, II, and III
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 1.1.2, subsection " Hello World!," in the course notes.
3.
Each of the following is a basic C++ type except
(a) bool
(b) char
(c) unsigned int
(d) byte
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 1.3.1 of the course notes.
4.
Which of the following statements might be produced by the decomposition of a pr
oblem into objects and relationships?
1. "A is a type of B"
2. "A B contains a C"

(a) I and II
(b) None
(c) II only
(d) I only
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 1.2.2, subsection "Decomposing the Representation," in the course no
tes.
5.
Suppose inf is an available ifstream and c is an available character. Consider t
he following code fragment.
do
c = inf.get();
while (!inf.eof() && isspace(c));
Which of the following accurately describes the effect of executing this fragmen
t?
(a) Characters are read until the end of the file is reached.
(b) Characters are read until a non-white-space character is read or until the e
nd of the file is reached.
(c) The number of non-white-space characters is counted.
(d) Characters are read until a white space is read.
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 1.3.3 of the course notes.
6.
In C++, the standard input stream is accessible using the object _____, and the
standard output stream is accessible using the object _____.
(a) stdin, stdout
(b) keyboard, screen
(c) input, output
(d) cin, cout
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 1.3.3, subsection "Using the Standard Streams," in the course notes.
7.
Consider the following C++ program segment.
#include <iostream>
#include <cstdlib>
using namespace std;
int main(int argc, char* argv[]) {
return EXIT_SUCCESS;
}
The first two lines of this program segment typically direct the preprocessor to
(a) compile two methods and prepare them for use by the program segment'
s source code
(b) define two macros available for use in the program segment
(c) define two keywords to aid in debugging the program segment
(d) include the contents of two files into the program segment's source code
Correct answer is

(d)

Your score on this question is:

0.00

Feedback:
See section 1.1.2, subsection " Phases of C++ Program Development," in the cours
e notes.
8.
In C++, the preprocessor is
(a) a tool that manipulates source files before compilation
(b) a virtual CPU that can be used to simulate machine-code execution
(c) a set of APIs provided by several compiler vendors
(d) a debugging tool common to most visual programming environments
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 1.3.4, subsection "Text Substitution," in the course notes.

9.
The purpose of a constructor is to
(a) initialize data members of a class properly after space has been all
ocated
(b) clean up memory when an instance goes out of scope
(c) handle assignments between instances of the class
(d) prevent memory leaks
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 1.3.2 of the course notes.
10.
The purpose of the assignment operator is to
(a) initialize data members when an instance is first created
(b) prevent memory leaks
(c) be used internally in an object's copy constructor
(d) provide for proper assignment between objects
Correct answer is

(d)

Your score o
1.
Which of the following statements properly allocates an array of 100 int
egers?
(a) int A = new int[100];
(b) int *A = new int[100];
(c) int *A = new (int) 100;
(d) int &A = new int[100];
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 1.3.1 of the course notes.
2.
Valid comments in C++ include which of the following?
1. /* comment */
2. / comment
3. // comment

(a) I, II, and III


(b) II and III only
(c) I and II only

(d) I and III only


Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 1.1.2, subsection " Hello World!," in the course notes.
3.
What is the type name used to represent single characters in C++?
(a) Character
(b) character
(c) char
(d) Char
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 1.3.1 of the course notes.
4.
In computer science, a structured representation of information is known as a(n)
(a) data structure
(b) cache
(c) algorithm
(d) processor
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 1.2.1, subsection "Data Structures," in the course notes.
5.
Which of the following is not a predefined stream object in C++?
(a) cin
(b) cfile
(c) cout
(d) cerr
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See Appendix A.4, page A-9, in the course notes.
6.
Suppose inf is an available ifstream and c is an available character. Consider t
he following code fragment.
do
c = inf.get();
while (!inf.eof() && isspace(c));
Which of the following accurately describes the effect of executing this fragmen
t?
(a) Characters are read until the end of the file is reached.
(b) Characters are read until a non-white-space character is read or until the e
nd of the file is reached.
(c) Characters are read until a white space is read.
(d) The number of non-white-space characters is counted.
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 1.3.3 of the course notes.
7.
In C++, the preprocessor is
(a) a set of APIs provided by several compiler vendors
(b) a virtual CPU that can be used to simulate machine-code execution
(c) a debugging tool common to most visual programming environments
(d) a tool that manipulates source files before compilation
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 1.3.4, subsection "Text Substitution," in the course notes.
8.

In C++, a preprocessor directive is a


(a) comment that prevents the linking of object files into executable pr
ograms
(b) comment ignored by the preprocessor
(c) command-line argument supplied to the linker
(d) single-line command introduced into a C++ source file
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 1.3.4, subsection "Text Substitution," in the course notes.
9.
Assume that Thing is a user-defined class, and consider the following code fragm
ent, where B is an instance of Thing.
Thing A = B;
Which of the following is a class member that is used in this code fragment?
(a) The default constructor
(b) The assignment operator
(c) The copy constructor
(d) The destructor
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 1.3.2 of the course notes.
10.
To which of the following is object-based programming ideally suited?
(a) Providing elegant mechanisms for code reuse
(b) Implementing simple monolithic programs
(c) Attaining the highest possible efficiency
(d) Encapsulation
Correct answer is

(d)

Your score on this question is:

0.00

Feedba
1.
Which of the following expressions evaluates to true in C++ if and only
if the index variable i is in bounds for an array of size 10?

(a) 0 < 10
(b) 0 <= i && i <= 10
(c) 0 <= i < 10
(d) 0 <= i && i < 10
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 1.3.1 of the course notes.
2.
At the end of the _____ stage for a C++ program, a(n) _____ can be produced.
(a) preprocessing, object file
(b) compiling, preprocessed file
(c) linking, executable image
(d) linking, source file
Correct answer is

(c)

Your score on this question is:

0.00

Feedback:
See section 1.1.2, subsection " Phases of C++ Program Development," in the cours
e notes.
3.
Each of the following is a basic C++ type except
(a) unsigned int
(b) char
(c) byte
(d) bool
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 1.3.1 of the course notes.
4.
Decomposition of a problem involves which of the following?
(a) Simplifying the problem by eliminating low-priority requirements
(b) Reverse-engineering an algorithm that solves a different problem
(c) Identifying entities and relationships that will aid in solving the problem
(d) Determining a programming language for implementing a solution to the proble
m

Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 1.2.2, subsection "Decomposing the Representation," in the course no
tes.

7.
One reason for using an assert statement such as
assert( 0 <= i && i < 10 );
within code is to
(a) provide a comment for the user
(b) terminate execution and send an error message whenever the condition is viol
ated
(c) send a warning message but continue execution when the condition is violated
(d) instruct the compiler to set i to any value in the indicated range
Correct answer is

(b)

Your score on this question is:


5.

10.00

In C++, the standard input stream is accessible using the object _____, and the
standard output stream is accessible using the object _____.
(a) keyboard, screen
(b) cin, cout
(c) input, output
(d) stdin, stdout
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 1.3.3, subsection "Using the Standard Streams," in the course notes.
6.
Suppose inf is an available ifstream and c is an available character. Consider t
he following code fragment.

do
c = inf.get();
while (!inf.eof() && isspace(c));
Which of the following accurately describes the effect of executing this fragmen
t?
(a) Characters are read until a white space is read.
(b) Characters are read until the end of the file is reached.
(c) Characters are read until a non-white-space character is read or until the e
nd of the file is reached.
(d) The number of non-white-space characters is counted.
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 1.3.3 of the course notes.
7.
Which of the following is the C++ preprocessor directive for file inclus
ion?
(a) #include
(b) #pragma
(c) #ifndef
(d) #define
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 1.3.4, subsection "File Inclusion," in the course notes.
8.
In C++, the directive #include is processed by the
(a) linker
(b) preprocessor
(c) Standard Template Library
(d) compiler
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 1.1.2, subsection "Phases of C++ Program Development," in the course
notes.

9.
Assume that Thing is a user-defined class, and consider the following code fragm
ent, where B is an instance of Thing.
Thing A = B;
Which of the following is a class member that is used in this code fragment?
(a) The default constructor
(b) The copy constructor
(c) The assignment operator
(d) The destructor
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 1.3.2 of the course notes.
10.
The purpose of a constructor is to
(a) handle assignments between instances of the class
(b) prevent memory leaks
(c) clean up memory when an instance goes out of scope
(d) initialize data members of a class properly after space has been allocated
Correct answer is

(d)

Your s
.
Which of the following statements properly allocates an array of 100 int
egers?
(a) int *A = new int[100];
(b) int *A = new (int) 100;
(c) int &A = new int[100];
(d) int A = new int[100];
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 1.4.3 of the course notes.
2.
Which of the following is true about variables with dynamic extent?
(a) They are
(b) They are created
(c) They are created
(d) They are created

destroyed only at the end of execution.


by the programmer, but destroyed by the compiler.
and destroyed by the compiler.
and destroyed by the programmer.

Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 1.4.3 of the course notes.
3.
What, if anything, is wrong with the following code fragment?
Thing *ptr = new Thing;
ptr = NULL;

(a) Nothing
(b) When executed, it will
reference to this instance
(c) When executed, it will
h NULL.
(d) When executed, it will
to a Thing.
Correct answer is

create an instance of Thing and then remove the only


without destroying it first.
create an instance of Thing and then overwrite it wit
assign a NULL pointer to a variable that is a pointer
(b)

Your score on this question is:

10.00

Feedback:
See section 1.4.3 of the course notes.
4.
Which of the following is true about the default parameter passing mecha
nism in C++?
(a) It is call-by-value.
(b) It is chosen automatically by the compiler.
(c) It is call-by-reference.
(d) It depends on where the function is defined.
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 1.4.2 of the course notes.
5.
Which of the following statements is true about a reference used as a function p
arameter?
(a) It allows a function to modify the original object passed in as the
argument.
(b) It passes a copy of the object.
(c) It is not as efficient as using a pointer.

(d) It cannot be used in a function prototype.


Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 1.4.2 of the course notes.
6.
Which of the following statements creates p as an alternative name for the varia
ble i?
(a) int &p = *i;
(b) int &p = i;
(c) int *p = i;
(d) int *p = &i;
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 1.4.2 of the course notes.
7.
Which of the following C++ operators is the address-of operator?
(a) *
(b) &
(c) !
(d) %
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 1.4.1 in the course notes.
8.
Which of the following declares p to be a pointer to an integer?
(a) int p;
(b) int p[]
(c) int **p;
(d) int *p;
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 1.4.1 of the course notes.
9.
What is the effect of the following C++ code fragment?
int A[100];
for( int *p = A; p < A + 100; ++p ) {
*p = 0;
}

(a) It sets 100 pointers in A to 0.


(b) It zeroes out A[0]-many elements of array A.
(c) It produces an out-of-bounds error.
(d) It zeroes out the 100 elements of array A.
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 1.4.1 of the course notes.
10.
Which of the following operations are valid for C++ pointer arithmetic?
1. Addition
2. Subtraction
3. Multiplication

(a) II only
(b) I only
(c) I and II only
(d) I, II, and III
Correct answer is

(c)

Your score on this question is:

10.00

Feedba
1.
Suppose a user-defined class Thing has a simple constructor that does no
t require any calls to new. Which of the following is true about the destructor?
(a) In this case, no destructor is required for class Thing.
(b) The appropriate destructor will be provided automatically by the compiler.
(c) It will not contain calls to delete.
(d) It might contain calls to delete, but might not.

Correct answer is

(d)

Your score on this question is:

0.00

Feedback:
See section 1.4.3 of the course notes.
2.
If A is an array of 100 integers, which of the following properly deallo
cates A?
(a) delete A;
(b) delete [100] A;
(c) delete A[100];
(d) delete [] A;
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 1.4.3 of the course notes.
3.
Each of the following C++ code fragments produces a memory leak except:
(a) int *A = new int[10]; delete A;
(b) int *A = new int[5]; A = 0; delete [] A;
(c) int *A = new int[10]; delete [] A;
(d) int *A = new int[5]; A = new int[5]; delete [] A;
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 1.4.3 of the course notes.
4.
Which of the following is true about the default parameter passing mecha
nism in C++?
(a) It is call-by-value.
(b) It is call-by-reference.
(c) It is chosen automatically by the compiler.
(d) It depends on where the function is defined.
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 1.4.2 of the course notes.
5.
Which of the following statements creates p as an alternative name for the varia
ble i?

(a) int &p = *i;


(b) int &p = i;
(c) int *p = &i;
(d) int *p = i;
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 1.4.2 of the course notes.
6.
Which of the following statements is true about a reference used as a function p
arameter?
(a) It passes a copy of the object.
(b) It is not as efficient as using a pointer.
(c) It cannot be used in a function prototype.
(d) It allows a function to modify the original object passed in as the argument
.
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 1.4.2 of the course notes.
7.
What is the effect of the following C++ code fragment?
int A[100];
for( int *p = A; p < A + 100; ++p ) {
*p = 0;
}

(a) It zeroes out the 100 elements of array A.


(b) It produces an out-of-bounds error.
(c) It zeroes out A[0]-many elements of array A.
(d) It sets 100 pointers in A to 0.
Correct answer is

(a)

Your score on this question is:


Feedback:
See section 1.4.1 of the course notes.
8.

10.00

Which of the following C++ operators is the dereference operator?


(a) &
(b) *
(c) %
(d) !
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 1.4.1 in the course notes.
9.
Which of the following declares p to be a pointer to an integer?
(a) int **p;
(b) int p[]
(c) int *p;
(d) int p;
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 1.4.1 of the course notes.
10.
Which of the following C++ operators is the address-of operator?
(a) %
(b) !
(c) &
(d) *
Correct answer is

(c)

Your score on this question is:

10.00

Feed
1.
Suppose a user-defined class Thing has a simple constructor that does no
t require any calls to new. Which of the following is true about the destructor?
(a) In this case, no destructor is required for class Thing.
(b) The appropriate destructor will be provided automatically by the compiler.
(c) It will not contain calls to delete.
(d) It might contain calls to delete, but might not.

Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 1.4.3 of the course notes.
2.
How does C++ handle memory allocation?
(a) C++ has a garbage collector that can be used or turned off.
(b) Allocation and deallocation is the responsibility of the programmer.
(c) C++ always uses a garbage collector.
(d) Allocation and deallocation is completely shielded from the programmer.
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 1.4.3 of the course notes.
3.
Which of the following statements properly allocates an array of 100 int
egers?
(a) int &A = new int[100];
(b) int A = new int[100];
(c) int *A = new (int) 100;
(d) int *A = new int[100];
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 1.4.3 of the course notes.
4.
Which of the following statements creates p as an alternative name for the varia
ble i?
(a) int *p = i;
(b) int &p = i;
(c) int *p = &i;
(d) int &p = *i;
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 1.4.2 of the course notes.
5.
Which of the following is true about the default parameter passing mecha
nism in C++?

(a) It is call-by-value.
(b) It depends on where the function is defined.
(c) It is call-by-reference.
(d) It is chosen automatically by the compiler.
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 1.4.2 of the course notes.
6.
Which of the following statements is true about a reference used as a function p
arameter?
(a) It passes a copy of the object.
(b) It cannot be used in a function prototype.
(c) It is not as efficient as using a pointer.
(d) It allows a function to modify the original object passed in as the argument
.
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 1.4.2 of the course notes.
7.
Consider the following C++ program segment:
int j[10];
for (int i = 0; i < 10; i++) {
j[i] = i;
}
int *a = j;
a++;
After execution of this program segment, what will be the value of j[0]?
(a) 1
(b) 11
(c) 0
(d) 2
Correct answer is

(c)

Your score on this question is:


Feedback:

10.00

See section 1.4.1 in the course notes.


8.
Which of the following declares p to be a pointer to an integer?
(a) int p;
(b) int *p;
(c) int p[]
(d) int **p;
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 1.4.1 of the course notes.
9.
Consider the following C++ program segment:
int j = 5;
int *a = &j;
*a = *a + 4;
After execution of this program segment, what will be the value of the variable
j?
(a) 0
(b) 9
(c) 4
(d) 5
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 1.4.1 in the course notes.
10.
Which of the following C++ operators is the dereference operator?
(a) &
(b) *
(c) %
(d) !
Correct answer is

(b)

Your score on this question is:

10.00

Fe
1.
Which of the following statements properly allocates an array of 100 int
egers?
(a) int *A = new (int) 100;
(b) int *A = new int[100];
(c) int &A = new int[100];
(d) int A = new int[100];
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 1.4.3 of the course notes.
2.
How does C++ handle memory allocation?
(a) Allocation and deallocation is completely shielded from the programm
er.
(b) Allocation and deallocation is the responsibility of the programmer.
(c) C++ always uses a garbage collector.
(d) C++ has a garbage collector that can be used or turned off.
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 1.4.3 of the course notes.
3.
If A is an array of 100 integers, which of the following properly deallo
cates A?
(a) delete A[100];
(b) delete [] A;
(c) delete [100] A;
(d) delete A;
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 1.4.3 of the course notes.
4.
Which of the following statements creates p as an alternative name for the varia
ble i?
(a) int &p = *i;
(b) int *p = i;
(c) int &p = i;

(d) int *p = &i;


Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 1.4.2 of the course notes.
5.
Which of the following statements is true about a reference used as a function p
arameter?
(a) It allows a function to modify the original object passed in as the
argument.
(b) It passes a copy of the object.
(c) It cannot be used in a function prototype.
(d) It is not as efficient as using a pointer.
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 1.4.2 of the course notes.
6.
Which of the following is true about the default parameter passing mecha
nism in C++?
(a) It is call-by-value.
(b) It is call-by-reference.
(c) It depends on where the function is defined.
(d) It is chosen automatically by the compiler.
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 1.4.2 of the course notes.
7.
What is the effect of the following C++ code fragment?
int A[100];
for( int *p = A; p < A + 100; ++p ) {
*p = 0;
}

(a) It zeroes out the 100 elements of array A.


(b) It zeroes out A[0]-many elements of array A.
(c) It sets 100 pointers in A to 0.

(d) It produces an out-of-bounds error.


Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 1.4.1 of the course notes.
8.
Consider the following C++ program segment:
int j[10];
for (int i = 0; i < 10; i++) {
j[i] = i;
}
int *a = j;
a++;
After execution of this program segment, what will be the value of j[0]?
(a) 2
(b) 0
(c) 11
(d) 1
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 1.4.1 in the course notes.
9.
Which of the following C++ operators is the address-of operator?
(a) %
(b) *
(c) !
(d) &
Correct answer is

(d)

Your score on this question is:


Feedback:
See section 1.4.1 in the course notes.

10.00

10.
Which of the following C++ operators is the dereference operator?
(a) %
(b) *
(c) !
(d) &
Correct answer is

(b)

Your score on this question is:

0.00

Fe
1.
Which of the following statements properly allocates an array of 100 int
egers?
(a) int *A = new int[100];
(b) int *A = new (int) 100;
(c) int &A = new int[100];
(d) int A = new int[100];
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 1.4.3 of the course notes.
2.
How does C++ handle memory allocation?
(a) C++ has a garbage collector that can be used or turned off.
(b) Allocation and deallocation is completely shielded from the programmer.
(c) C++ always uses a garbage collector.
(d) Allocation and deallocation is the responsibility of the programmer.
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 1.4.3 of the course notes.
3.
Suppose a user-defined class Thing has a simple constructor that does no
t require any calls to new. Which of the following is true about the destructor?
(a) It will not contain calls to delete.
(b) In this case, no destructor is required for class Thing.
(c) The appropriate destructor will be provided automatically by the compiler.
(d) It might contain calls to delete, but might not.
Correct answer is

(d)

Your score on this question is:

0.00

Feedback:
See section 1.4.3 of the course notes.
4.
Which of the following is true about the default parameter passing mecha
nism in C++?
(a) It depends on where the function is defined.
(b) It is call-by-reference.
(c) It is chosen automatically by the compiler.
(d) It is call-by-value.
Correct answer is

(d)

Your score on this question is:

0.00

Feedback:
See section 1.4.2 of the course notes.
5.
Which of the following statements is true about a reference used as a function p
arameter?
(a) It cannot be used in a function prototype.
(b) It is not as efficient as using a pointer.
(c) It passes a copy of the object.
(d) It allows a function to modify the original object passed in as the argument
.
Correct answer is

(d)

Your score on this question is:

0.00

Feedback:
See section 1.4.2 of the course notes.
6.
Assume that Thing is a user-defined type. Which of the following print f
unctions for Thing is the safest and most efficient?
(a) void print( const Thing& x );
(b) void print( Thing x );
(c) void print( Thing& x );
(d) void print( Thing* x );
Correct answer is

(a)

Your score on this question is:


Feedback:
See section 1.4.2 of the course notes.
7.

10.00

Consider the following C++ program segment:


int j = 5;
int *a = &j;
*a = *a + 4;
After execution of this program segment, what will be the value of the variable
j?
(a) 9
(b) 0
(c) 4
(d) 5
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 1.4.1 in the course notes.
8.
What is the effect of the following C++ code fragment?
int A[100];
for( int *p = A; p < A + 100; ++p ) {
*p = 0;
}

(a) It produces an out-of-bounds error.


(b) It zeroes out A[0]-many elements of array A.
(c) It zeroes out the 100 elements of array A.
(d) It sets 100 pointers in A to 0.
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 1.4.1 of the course notes.
9.
Which of the following declares p to be a pointer to an integer?
(a) int p;
(b) int *p;
(c) int p[]
(d) int **p;
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 1.4.1 of the course notes.
10.
Which of the following operations are valid for C++ pointer arithmetic?
1. Addition
2. Subtraction
3. Multiplication

(a) I and II only


(b) II only
(c) I only
(d) I, II, and III
Correct answer is

(a)

Your score on this question is:

10.00

Fe
1.
Which of the following expressions evaluates to true in C++ if and only if the
index variable i is in bounds for an array of size 10?
(a) 0 <= i && i < 10
(b) 0 <= i < 10
(c) 0 <= i && i <= 10
(d) 0 < 10
Correct answer is (a)
Your score on this question is: 10.00
Feedback:
See section 1.3.1 of the course notes.
2.
C++ supports which of the following features?
1. Classes
2. Inheritance
3. Exceptions

(a) I, II, and III


(b) III only
(c) II and III only
(d) None

Correct answer is

(a)

Your score on this question is:

10.00

-------------------------------------------------------------------------------2.
Valid comments in C++ include which of the following?
/* comment */
/ comment
// comment

(a) I, II, and III


(b) I and III only
(c) I and II only
(d) II and III only
Correct answer is (b)
Your score on this question is: 10.00
Feedback:
See section 1.1.2, subsection " Hello World!," in the course notes.

-------------------------------------------------------------------------------3.
What is the type name used to represent extra precision real numbers in C++?
(a) long float
(b) double
(c) float
(d) real
Correct answer is (b)
Your score on this question is: 10.00
Feedback:
See section 1.3.1 of the course notes.
-------------------------------------------------------------------------------4.
Lines at a store, file cabinets, and bookcases are real-world entities that mos
t resemble _____ in computer science.

(a) functional programming languages


(b) data structures
(c) algorithms
(d) object-oriented programming languages
Correct answer is (b)
Your score on this question is: 10.00
Feedback:
See section 1.2.1, subsection "Data Structures," in the course notes.

-------------------------------------------------------------------------------5.
Suppose inf is an available ifstream and c is an available character. Consider
the following code fragment.
do
c = inf.get();
while (!inf.eof() && isspace(c));
Which of the following accurately describes the effect of executing this fragmen
t?

(a) The number of non-white-space characters is counted.


(b) Characters are read until a non-white-space character is read or until the
end of the file is reached.
(c) Characters are read until a white space is read.
(d) Characters are read until the end of the file is reached.
Correct answer is (b)
Your score on this question is: 10.00
Feedback:
See section 1.3.3 of the course notes.
-------------------------------------------------------------------------------6.
To read data from a file into a C++ program using class ifstream, it is necessa
ry to include the _____ library header file.

(a) fstream
(b) ctype
(c) string
(d) iomanip
Correct answer is (a)

Your score on this question is: 10.00


Feedback:
See Appendix A.4, page A-13, in the course notes.
9.
In a C++ class, access to data members and function members are typicall
y
(a) both public
(b) both private
(c) public and private, respectively
(d) private and public, respectively
Correct answer is

(d)

Your score on this question is:

0.00

-------------------------------------------------------------------------------7.
Consider the following C++ program segment.
#include <iostream>
#include <cstdlib>
using namespace std;
int main(int argc, char* argv[]) {
return EXIT_SUCCESS;
}
The first two lines of this program segment typically direct the preprocessor to

(a) define two macros available for use in the program segment
(b) include the contents of two files into the program segment's source code
(c) define two keywords to aid in debugging the program segment
(d) compile two methods and prepare them for use by the program segment's sourc
e code
Correct answer is (b)
Your score on this question is: 10.00
Feedback:
See section 1.1.2, subsection " Phases of C++ Program Development," in the cours
e notes.

-------------------------------------------------------------------------------8.

In C++, preprocessor directives begin with which of the following symbols?


(a) ?
(b) %
(c) #
(d) Correct answer is (c)
Your score on this question is: 10.00
Feedback:
See section 1.3.4, subsection "Text Substitution," in the course notes.

-------------------------------------------------------------------------------9.
If a user-defined class Complex has overloaded operator+=, then one would expec
t this operator to have which of the following declarations?
(a) Complex& operator+=( const Complex rhs );
(b) void operator+=( float real, float imag );
(c) void operator+=( const Complex& rhs );
(d) Complex& operator+=( const Complex& rhs );
Correct answer is (d)
Your score on this question is: 10.00
Feedback:
See section 1.3.2 of the course notes.
-------------------------------------------------------------------------------10.
Assume that Thing is a user-defined class, and consider the following code frag
ment, where B is an instance of Thing.
Thing A = B;
Which of the following is a class member that is used in this code fragment?

(a) The destructor


(b) The copy constructor
(c) The default constructor
(d) The assignment operator
Correct answer is (b)
Your score on this question is: 10.00
Feedback:

See section 1.3.2 of the course notes.


1.
What, if anything, is wrong with the following code fragment?
Thing *ptr = new Thing;
ptr = NULL;

(a) Nothing
(b) When executed, it will
r to a Thing.
(c) When executed, it will
reference to this instance
(d) When executed, it will
th NULL.

assign a NULL pointer to a variable that is a pointe


create an instance of Thing and then remove the only
without destroying it first.
create an instance of Thing and then overwrite it wi

Correct answer is (c)


Your score on this question is: 10.00
Feedback:
See section 1.4.3 of the course notes.

-------------------------------------------------------------------------------2.
How does C++ handle memory allocation?
(a) C++ has a
(b) Allocation
(c) C++ always
(d) Allocation

garbage collector that can be used or turned off.


and deallocation is completely shielded from the programmer.
uses a garbage collector.
and deallocation is the responsibility of the programmer.

Correct answer is (d)


Your score on this question is: 10.00
Feedback:
See section 1.4.3 of the course notes.
-------------------------------------------------------------------------------3.
Which of the following is true about variables with dynamic extent?
(a) They are destroyed only at the end of execution.
(b) They are created and destroyed by the compiler.
(c) They are created and destroyed by the programmer.
(d) They are created by the programmer, but destroyed by the compiler.

Correct answer is (c)


Your score on this question is: 10.00
Feedback:
See section 1.4.3 of the course notes.
-------------------------------------------------------------------------------4.
Which of the following statements is true about a reference used as a function
parameter?

(a) It is not as efficient as using a pointer.


(b) It passes a copy of the object.
(c) It allows a function to modify the original object passed in as the argumen
t.
(d) It cannot be used in a function prototype.
Correct answer is (c)
Your score on this question is: 10.00
Feedback:
See section 1.4.2 of the course notes.
-------------------------------------------------------------------------------5.
Which of the following is true about the default parameter passing mechanism in
C++?
(a) It is call-by-reference.
(b) It is chosen automatically by the compiler.
(c) It depends on where the function is defined.
(d) It is call-by-value.
Correct answer is (d)
Your score on this question is: 10.00
Feedback:
See section 1.4.2 of the course notes.
-------------------------------------------------------------------------------6.
Which of the following statements creates p as an alternative name for the vari
able i?

(a) int *p = &i;


(b) int *p = i;

(c) int &p = i;


(d) int &p = *i;
Correct answer is (c)
Your score on this question is: 10.00
Feedback:
See section 1.4.2 of the course notes.
-------------------------------------------------------------------------------7.
Consider the following C++ program segment:
int j = 5;
int *a = &j;
*a = *a + 4;
After execution of this program segment, what will be the value of the variable
j?

(a) 5
(b) 9
(c) 0
(d) 4
Correct answer is (b)
Your score on this question is: 10.00
Feedback:
See section 1.4.1 in the course notes.

-------------------------------------------------------------------------------8.
Consider the following C++ program segment:
int j[10];
for (int i = 0; i < 10; i++) {
j[i] = i;
}
int *a = j;
a++;
After execution of this program segment, what will be the value of j[0]?

(a) 2
(b) 11
(c) 0
(d) 1
Correct answer is (c)

Your score on this question is: 10.00


Feedback:
See section 1.4.1 in the course notes.

-------------------------------------------------------------------------------9.
Which of the following C++ operators is the dereference operator?

(a) !
(b) *
(c) %
(d) &
Correct answer is (b)
Your score on this question is: 10.00
Feedback:
See section 1.4.1 in the course notes.

-------------------------------------------------------------------------------10.
Which of the following declares p to be a pointer to an integer?
(a) int *p;
(b) int p[]
(c) int **p;
(d) int p;
Correct answer is (a)
Your score on this question is: 10.00
Feedback:
See section 1.4.1 of the course notes.
1.
Each of the following C++ code fragments produces a memory leak except:
(a) int *A = new int[10]; delete [] A;
(b) int *A = new int[5]; A = new int[5]; delete [] A;
(c) int *A = new int[5]; A = 0; delete [] A;
(d) int *A = new int[10]; delete A;
Correct answer is (a)

Your score on this question is: 10.00


Feedback:
See section 1.4.3 of the course notes.

-------------------------------------------------------------------------------2.
What, if anything, is wrong with the following code fragment?
Thing *ptr = new Thing;
ptr = NULL;

(a) When executed, it will create an instance of Thing and then remove the onl
y reference to this instance without destroying it first.
(b) When executed, it will create an instance of Thing and then overwrite it wi
th NULL.
(c) When executed, it will assign a NULL pointer to a variable that is a pointe
r to a Thing.
(d) Nothing
Correct answer is (a)
Your score on this question is: 10.00
Feedback:
See section 1.4.3 of the course notes.
-------------------------------------------------------------------------------3.
If A is an array of 100 integers, which of the following properly deallocates A
?
(a) delete [100] A;
(b) delete A;
(c) delete A[100];
(d) delete [] A;
Correct answer is (d)
Your score on this question is: 10.00
Feedback:
See section 1.4.3 of the course notes.
-------------------------------------------------------------------------------4.
Which of the following statements is true about a reference used as a function
parameter?

(a) It passes a copy of the object.


(b) It is not as efficient as using a pointer.
(c) It cannot be used in a function prototype.
(d) It allows a function to modify the original object passed in as the argumen
t.
Correct answer is (d)
Your score on this question is: 10.00
Feedback:
See section 1.4.2 of the course notes.
-------------------------------------------------------------------------------5.
Which of the following statements creates p as an alternative name for the vari
able i?

(a) int &p = *i;


(b) int *p = i;
(c) int &p = i;
(d) int *p = &i;
Correct answer is (c)
Your score on this question is: 10.00
Feedback:
See section 1.4.2 of the course notes.
-------------------------------------------------------------------------------6.
Which of the following is true about the default parameter passing mechanism in
C++?
(a) It is call-by-value.
(b) It is call-by-reference.
(c) It is chosen automatically by the compiler.
(d) It depends on where the function is defined.
Correct answer is (a)
Your score on this question is: 10.00
Feedback:
See section 1.4.2 of the course notes.
--------------------------------------------------------------------------------

7.
Which of the following C++ operators is the dereference operator?

(a) &
(b) %
(c) !
(d) *
Correct answer is (d)
Your score on this question is: 10.00
Feedback:
See section 1.4.1 in the course notes.

-------------------------------------------------------------------------------8.
Consider the following C++ program segment:
int j[10];
for (int i = 0; i < 10; i++) {
j[i] = i;
}
int *a = j;
a++;
After execution of this program segment, what will be the value of j[0]?

(a) 0
(b) 1
(c) 11
(d) 2
Correct answer is (a)
Your score on this question is: 10.00
Feedback:
See section 1.4.1 in the course notes.

-------------------------------------------------------------------------------9.
What is the effect of the following C++ code fragment?
int A[100];
for( int *p = A; p < A + 100; ++p ) {
*p = 0;
}

(a) It zeroes out A[0]-many elements of array A.


(b) It zeroes out the 100 elements of array A.
(c) It produces an out-of-bounds error.
(d) It sets 100 pointers in A to 0.
Correct answer is (b)
Your score on this question is: 10.00
Feedback:
See section 1.4.1 of the course notes.
-------------------------------------------------------------------------------10.
Which of the following operations are valid for C++ pointer arithmetic?
Addition
Subtraction
Multiplication

(a) I only
(b) I, II, and III
(c) II only
(d) I and II only
Correct answer is (d)
Your score on this question is: 10.00
Feedback:
See section 1.4.1 in the course notes.

1.
Which of the following is necessary in order to obtain polymorphic behav
ior in C++?
(a) Pointers or references are used with virtual functions.
(b) Only instances of the base class are used.
(c) Templates are avoided.
(d) Only instances of the derived class are used.
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 1.5.2 of the course notes.
2.
Under what circumstances will a member function in C++ display polymorph

ic behavior?
(a) Always
(b) If and only if the class is not a template class
(c) If and only if the function is explicitly declared to be virtual
(d) If and only if the class uses private inheritance
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 1.5.2 of the course notes.
3.
Consider the following inheritance declarations.
class Base
{ public: int x; private: int y; };
class Derived: public Base { public: int z; };
Derived D;
Under these declarations, which of the following statements, if any, will fail t
o compile?
(a) D.y = 555;
(b) D.x = 555;
(c) D.z = 555;
(d) None
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 1.5.1 of the course notes.
4.
Inheritance is an important feature of C++ because
(a) it greatly increases efficiency
(b) it can often replace templates
(c) it is a powerful code reuse mechanism
(d) it makes type-checking much easier
Correct answer is

(c)

Your score on this question is:


Feedback:
See section 1.5.1 of the course notes.
5.
Consider the following C++ program segment:
try {

10.00

throw out_of_range("out of range");


cout << "try ";
}
catch (...) {
cout << "catch ";
}
The above program segment will output which of the following character strings?
(a) "catch "
(b) "try catch "
(c) "catch try "
(d) "out of range catch "
Correct answer is

(a)

Your score on this question is:

0.00

Feedback:
See section 1.5.4 in the course notes.
6.
In the C++ standard exception hierarchy, which of the following classes is deriv
ed from class logic_error?
(a) underflow_error
(b) bad_cast
(c) bad_alloc
(d) length_error
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 1.5.4, subsection "The C++ Standard Exception Hierarchy," in the cou
rse notes.
7.
Consider the following outline of a template array class.
template<class T> class Array { ... }
Which of the following declarations are in error with respect to using such a cl
ass?
1. Array<Array<int> > A;
2. Array<Array<int>*> A;

3. Array<int**> A;

(a) II only
(b) III only
(c) None
(d) I only
Correct answer is

(c)

Your score on this question is:

0.00

Feedback:
See section 1.5.3 of the course notes.
8.
Consider the following partial C++ templated class definition.
template<class A, class B>
class ...
The line of code template<class A, class B> will generally be followed by
(a) a class definition that defines a subtype of the template classes A
B.
the definition of a class called A that uses the generic type parameter B.
a class definition containing the generic type parameters A and B.
definitions of a class called A and a class called B.

and
(b)
(c)
(d)

Correct answer is

(c)

Your score on this question is:

0.00

Feedback:
See section 1.5.3 in the course notes.
9.
Which of the following is (are) true about template classes in C++?
1. Methods cannot be overloaded in templated class definitions.
2. Private data of a templated class cannot be declared to have the type of t
he templated parameter.

(a) I only
(b) I and II
(c) II only
(d) None
Correct answer is

(d)

Your score on this question is:


Feedback:

0.00

See section 1.5.3 of the course notes


10.
Consider the following template swap function and data types.
template<class T> void swap( T& a, T& b ){
T tmp = a; a = b; b = tmp;
}
char c1, c2;
int
i1, i2;
float A[10];
Which of the following calls to swap produces a compile time error?
1. swap( i1, c2 )
2. swap( c1, i2 );
3. swap( A[5], A[2] );

(a) I, II, and III


(b) II and III
(c) I and II
(d) I only
Correct answer is

(c)

Your score on this question is:

0.00

Feedback:
See section 1.5.3 of the course notes.
1.
In C++, the ability for an entity to assume different types is known as
(a) polymorphism
(b) static binding
(c) inheritance
(d) composition
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 1.5.2 of the course notes.
2.
Which of the following is an example of a pure virtual function?
(a) virtual int Compute() { return 0; };

(b) virtual int Compute();


(c) virtual int Compute() = 0;
(d) int Compute() { Compute = 0; };
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 1.5.2 of the course notes.
3.
Consider the following inheritance declarations.
class Base
{ public: int x; private: int y; };
class Derived: public Base { public: int z; };
Derived D;
Under these declarations, which of the following statements, if any, will fail t
o compile?
(a) D.x = 555;
(b) None
(c) D.y = 555;
(d) D.z = 555;
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 1.5.1 of the course notes.
4.
What is composition?
(a) It is an important idea in Object Oriented Programming, but currentl
y it is not implemented in C++.
(b) It is the inclusion of one class in another as a data member.
(c) It is the same as polymorphism.
(d) It is a method to build new classes on top of existing ones.
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 1.5.1 of the course notes.
5.
Consider the following C++ program segment:
try {
throw out_of_range("out of range");
}
catch (runtime_error& e) {
cout << e.what();

}
catch (...) {
cout << "exception encountered";
}
The above program segment will output which of the following character strings?
(a) "what"
(b) "runtime error"
(c) "exception encountered"
(d) "out of range"
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 1.5.4 in the course notes.
6.
In C++ exception handling, intermediate exception handlers typically are used to
:
(a) throw user-defined exception classes
(b) override the guarantees of exception specifications
(c) catch exceptions polymorphically
(d) ensure allocated resources are properly released
Correct answer is

(d)

Your score on this question is:

0.00

Feedback:
See section 1.5.4, subsection "Using Intermediate Handlers," in the course notes
.
7.
Consider the following definitions of a C++ class.
class Array {
public:
typedef float Item;
// <-- change here
Item& operator[](int i) {return arr[i];}
private:
int
len; // length of array
Item *arr; // pointer to first elm
};
template<class T>
class Array {
public:

T& operator[](int i) {return arr[i];}


private:
int len;
T *arr; };
The second definition of class Array is _____ versatile than the first _____ eff
icient at run time when used in a program.
(a) more, and equally
(b) more, but less
(c) less, but less
(d) less, and equally
Correct answer is

(a)

Your score on this question is:

0.00

Feedback:
See section 1.5.3 of the course notes.
8.
In a template definition
template<class T> ...
the template parameter T ranges over
(a) only user-defined classes
(b) all types
(c) only built-in types
(d) classes as well as structs
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 1.5.3 of the course notes.
9.
Which of the following describes a difference between template functions and tem
plate classes in C++?
(a) Template classes cannot be defined for user-defined types, but templ
ate functions can.
(b) Template functions cannot be defined for user-defined types, but template cl
asses can.
(c) The compiler generates a separate definition for each template function at c
ompile time, but template classes for different types are created at run time.
(d) The compiler determines the types of a template function's arguments, but th
e types of template classes must be stated explicitly when declaring objects.
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 1.5.3 of the course notes.
10.
Consider the following template array-copy function and arrays.
template<class T> void copy( T a[], T b[], int n ) {
for(int i = 0; i < n; i++ ) a[i] = b[i];
}
char C[10], CC[10];
int
I[10];
float F[10];
Which of the following calls to copy would produce a compile time error?
(a) copy( I, F, 10 );
(b) copy( C, CC, 10 );
(c) copy( I, I, 10 );
(d) copy( I, (int*)F, 10 );
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 1.5.3 of the course notes.

1.
Under what circumstances will a member function in C++ display polymorph
ic behavior?
(a) If and only if the class is not a template class
(b) If and only if the function is explicitly declared to be virtual
(c) If and only if the class uses private inheritance
(d) Always
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 1.5.2 of the course notes.
2.
Which of the following is an example of a pure virtual function?
(a) virtual int Compute() = 0;
(b) int Compute() { Compute = 0; };
(c) virtual int Compute();
(d) virtual int Compute() { return 0; };

Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 1.5.2 of the course notes.
3.
Consider the following inheritance declarations.
class Base
{ public: int x; private: int y; };
class Derived: public Base { public: int z; };
Derived D;
Under these declarations, which of the following statements, if any, will fail t
o compile?
(a) None
(b) D.y = 555;
(c) D.x = 555;
(d) D.z = 555;
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 1.5.1 of the course notes.
4.
Inheritance is an important feature of C++ because
(a) it is a powerful code reuse mechanism
(b) it makes type-checking much easier
(c) it can often replace templates
(d) it greatly increases efficiency
Correct answer is

(a)

Your score on this question is:


Feedback:
See section 1.5.1 of the course notes.
5.
Consider the following C++ program segment:
try {
throw out_of_range("out of range");
cout << "try ";
}
catch (...) {
cout << "catch ";
}

10.00

The above program segment will output which of the following character strings?
(a) "catch try "
(b) "out of range catch "
(c) "catch "
(d) "try catch "
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 1.5.4 in the course notes.
6.
In C++ exception handling, intermediate exception handlers typically are used to
:
(a) override the guarantees of exception specifications
(b) throw user-defined exception classes
(c) catch exceptions polymorphically
(d) ensure allocated resources are properly released
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 1.5.4, subsection "Using Intermediate Handlers," in the course notes
.
7.
What is the purpose of class templates?
(a) To avoid the use of dangerous pointers
(b) To improve the portability of code
(c) To increase the efficiency of the class methods
(d) To easily specify a group of related classes
Correct answer is

(d)

Your score on this question is:


Feedback:
See section 1.5.3 of the course notes.
8.

0.00

Consider the following outline of a template array class.


template<class T> class Array { ... }
Which of the following is true about using this outline to implement a general c
ontainer class?
(a) It is a reasonable way to implement such a class.
(b) It is a poor choice since templates slow down compilation.
(c) It is a poor choice since the type matching will slow down access at runtime
.
(d) It is impossible since the algorithm cannot know how to copy an instance of
type T.
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 1.5.3 of the course notes.
9.
Consider the following definitions of a C++ class.
class Array {
public:
typedef float Item;
// <-- change here
Item& operator[](int i) {return arr[i];}
private:
int
len; // length of array
Item *arr; // pointer to first elm
};
template<class T>
class Array {
public:
T& operator[](int i) {return arr[i];}
private:
int len;
T *arr; };
The second definition of class Array is _____ versatile than the first _____ eff
icient at run time when used in a program.
(a) more, but less
(b) more, and equally
(c) less, but less
(d) less, and equally
Correct answer is

(b)

Your score on this question is:


Feedback:
See section 1.5.3 of the course notes.
10.

10.00

Consider the following template swap function and data types.


template<class T> void swap( T& a, T& b ){
T tmp = a; a = b; b = tmp;
}
char c1, c2;
int
i1, i2;
float A[10];
Which of the following calls to swap produces a compile time error?
1. swap( i1, c2 )
2. swap( c1, i2 );
3. swap( A[5], A[2] );

(a) I only
(b) II and III
(c) I, II, and III
(d) I and II
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 1.5.3 of the course notes.
1.
In C++, the ability for an entity to assume different types is known as
(a) inheritance
(b) static binding
(c) polymorphism
(d) composition
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 1.5.2 of the course notes.
2.
Which of the following is an example of a pure virtual function?
(a) virtual int Compute() { return 0; };
(b) virtual int Compute();
(c) virtual int Compute() = 0;
(d) int Compute() { Compute = 0; };

Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 1.5.2 of the course notes.
3.
What is the role of the destructor for the base class when an instance o
f a derived class goes out of scope?
(a) It is called automatically.
(b) It must be called by the user, unless the derived class uses dynamic memory
(the heap).
(c) It is available to be called by the user to prevent the destructor for the d
erived class from being called.
(d) It will not be called and it cannot be called at such a time.
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 1.5.2 of the course notes.
4.
Consider the following inheritance declarations.
class Base
{ public: int x; private: int y; };
class Derived: public Base { public: int z; };
Derived D;
Under these declarations, which of the following statements, if any, will fail t
o compile?
(a) None
(b) D.y = 555;
(c) D.x = 555;
(d) D.z = 555;
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 1.5.1 of the course notes.
5.
Consider the following C++ program segment:
try {
throw out_of_range("out of range");
}
catch (runtime_error& e) {
cout << e.what();
}

catch (...) {
cout << "exception encountered";
}
The above program segment will output which of the following character strings?
(a) "exception encountered"
(b) "runtime error"
(c) "out of range"
(d) "what"
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 1.5.4 in the course notes.
6.
In the C++ standard exception hierarchy, which of the following classes is deriv
ed from class logic_error?
(a) length_error
(b) underflow_error
(c) bad_alloc
(d) bad_cast
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 1.5.4, subsection "The C++ Standard Exception Hierarchy," in the cou
rse notes.
7.
Consider the following partial C++ templated class definition.
template<class A, class B>
class ...
The line of code template<class A, class B> will generally be followed by
(a) a class definition containing the generic type parameters A and B.
(b) a class definition that defines a subtype of the template classes A and B.
(c) the definition of a class called A that uses the generic type parameter B.
(d) definitions of a class called A and a class called B.
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 1.5.3 in the course notes.
8.
Which of the following describes a difference between template functions and tem
plate classes in C++?
(a) Template classes cannot be defined for user-defined types, but templ
ate functions can.
(b) Template functions cannot be defined for user-defined types, but template cl
asses can.
(c) The compiler determines the types of a template function's arguments, but th
e types of template classes must be stated explicitly when declaring objects.
(d) The compiler generates a separate definition for each template function at c
ompile time, but template classes for different types are created at run time.
Correct answer is

(c)

Your score on this question is:

0.00

Feedback:
See section 1.5.3 of the course notes.
9.
Consider the following outline of a template array class.
template<class T> class Array { ... }
Which of the following is true about using this outline to implement a general c
ontainer class?
(a) It is a poor choice since the type matching will slow down access at
runtime.
(b) It is a poor choice since templates slow down compilation.
(c) It is a reasonable way to implement such a class.
(d) It is impossible since the algorithm cannot know how to copy an instance of
type T.
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 1.5.3 of the course notes.
10.
Consider the following template swap function and data types.
template<class T> void swap( T& a, T& b ){
T tmp = a; a = b; b = tmp;
}

char c1, c2;


int
i1, i2;
float A[10];
Which of the following calls to swap produces a compile time error?
1. swap( i1, c2 )
2. swap( c1, i2 );
3. swap( A[5], A[2] );

(a) II and III


(b) I only
(c) I and II
(d) I, II, and III
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 1.5.3 of the course notes.
1.
Polymorphism is a mechanism that is used in order to
(a) determine methods of a class based on its data members
(b) determine the type of an object dynamically at run time
(c) protect data members from illegal access
(d) build new classes on top of existing ones
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 1.5.2 of the course notes.
2.
Under what circumstances will a member function in C++ display polymorph
ic behavior?
(a) If and only if the class is not a template class
(b) If and only if the function is explicitly declared to be virtual
(c) If and only if the class uses private inheritance
(d) Always
Correct answer is

(b)

Your score on this question is:


Feedback:
See section 1.5.2 of the course notes.

10.00

3.
Consider the following inheritance declarations.

class Base
{ public: int x; private: int y; };
class Derived: public Base { public: int z; };
Derived D;
Under these declarations, which of the following statements, if any, will fail t
o compile?
(a) D.x = 555;
(b) None
(c) D.z = 555;
(d) D.y = 555;
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 1.5.1 of the course notes.
4.
Which of the following is true of inheritance?
(a) It provides for the elegant construction of a new class from an exis
ting class.
(b) It is an important idea in Object Oriented Programming, but currently it is
not implemented in C++.
(c) It causes one type to behave like several types.
(d) It protects data members from illegal access.
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 1.5.1 of the course notes.
5.
Consider the following C++ program segment:
try {
throw out_of_range("out of range");
}
catch (runtime_error& e) {
cout << e.what();
}
catch (...) {
cout << "exception encountered";
}
The above program segment will output which of the following character strings?
(a) "exception encountered"
(b) "runtime error"
(c) "out of range"
(d) "what"
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 1.5.4 in the course notes.
6.
Which of the following statements regarding C++ exception specifications is (are
) true?
1. An exception specification can guarantee that a function does not throw an
y exceptions.
2. An exception specification can permit a function to throw any type of exce
ption.

(a) None
(b) II only
(c) I and II
(d) I only
Correct answer is

(c)

Your score on this question is:

0.00

Feedback:
See section 1.5.4, subsection "The C++ Standard Exception Hierarchy," in the cou
rse notes.
7.
Which of the following is true about compilation of a template function
or class?
(a) Compilation takes much, much longer.
(b) Compilation takes slightly longer.
(c) Templates are not handled during compilation.
(d) Compilation takes less time.
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 1.5.3 of the course notes.
8.
Consider the following partial C++ templated class definition.
template<class A, class B>
class ...
The line of code template<class A, class B> will generally be followed by

(a) the definition of a class called A that uses the generic type parame
B.
a class definition that defines a subtype of the template classes A and B.
definitions of a class called A and a class called B.
a class definition containing the generic type parameters A and B.

ter
(b)
(c)
(d)

Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 1.5.3 in the course notes.
9.
The proper tool for writing an array class that can have some instances
with integer elements and other instances with float elements is the use of
(a) unions
(b) inheritance
(c) casting
(d) templates
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 1.5.3 of the course notes.
10.
The purpose of function templates is to
(a) increase the efficiency of various algorithms
(b) help the type-checker search for errors
(c) replace generic void* pointers in C
(d) easily specify a family of operationally equivalent functions
Correct answer is

(d)

Your score on this question is:

0.00

Feedback:
See section 1.5.3 of the course notes.

1.
Which of the following is necessary in order to obtain polymorphic behav
ior in C++?
(a) Only instances of the base class are used.
(b) Only instances of the derived class are used.
(c) Pointers or references are used with virtual functions.
(d) Templates are avoided.
Correct answer is

(c)

Your score on this question is:


Feedback:

10.00

See section 1.5.2 of the course notes.


2.
Which of the following is an example of a pure virtual function?
(a) virtual int Compute() = 0;
(b) int Compute() { Compute = 0; };
(c) virtual int Compute() { return 0; };
(d) virtual int Compute();
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 1.5.2 of the course notes.
3.
What is the role of the destructor for the base class when an instance o
f a derived class goes out of scope?
(a) It will not be called and it cannot be called at such a time.
(b) It is available to be called by the user to prevent the destructor for the d
erived class from being called.
(c) It is called automatically.
(d) It must be called by the user, unless the derived class uses dynamic memory
(the heap).
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 1.5.2 of the course notes.
4.
Consider the following inheritance declarations.
class Base
{ public: int x; private: int y; };
class Derived: public Base { public: int z; };
Derived D;
Under these declarations, which of the following statements, if any, will fail t
o compile?
(a) D.x = 555;
(b) D.y = 555;
(c) D.z = 555;
(d) None
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 1.5.1 of the course notes.
5.
In the C++ standard exception hierarchy, which of the following classes is not d
erived from class runtime_error?
(a) overflow_error
(b) underflow_error
(c) domain_error
(d) range_error
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 1.5.4, subsection "The C++ Standard Exception Hierarchy," in the cou
rse notes.
6.
In the C++ standard exception hierarchy, which of the following classes is deriv
ed from class logic_error?
(a) bad_alloc
(b) underflow_error
(c) bad_cast
(d) length_error
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 1.5.4, subsection "The C++ Standard Exception Hierarchy," in the cou
rse notes.
7.
Consider the following partial C++ template class definition.
template<class T>
class Array {
public:
T& operator[](int i) {return arr[i];}
...
private:

int len;

*arr;

};

Which of the following is a (are) correct template instantiation(s)?


1. Array<int> A;
2. Array<double> A;
3. Array<Array<int> > A;

(a) I only
(b) II only
(c) I and II only
(d) I, II, and III
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 1.5.3 of the course notes.
8.
The proper tool for writing an array class that can have some instances
with integer elements and other instances with float elements is the use of
(a) inheritance
(b) unions
(c) templates
(d) casting
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 1.5.3 of the course notes.
9.
Consider the following partial C++ templated class definition.
template<class A, class B>
class ...
The line of code template<class A, class B> will generally be followed by
(a) the definition of a class called A that uses the generic type parame
B.
a class definition containing the generic type parameters A and B.
a class definition that defines a subtype of the template classes A and B.
definitions of a class called A and a class called B.

ter
(b)
(c)
(d)

Correct answer is

(b)

Your score on this question is:


Feedback:
See section 1.5.3 in the course notes.

10.00

10.
The purpose of function templates is to
(a) increase the efficiency of various algorithms
(b) easily specify a family of operationally equivalent functions
(c) replace generic void* pointers in C
(d) help the type-checker search for errors
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 1.5.3 of the course notes.
1.
Suppose inf is an available ifstream and c is an available character. Consider t
he following code fragment.
do
c = inf.get();
while (!inf.eof() && isspace(c));
Which of the following accurately describes the effect of executing this fragmen
t?
(a) Characters are read until the end of the file is reached.
(b) Characters are read until a non-white-space character is read or until the e
nd of the file is reached.
(c) Characters are read until a white space is read.
(d) The number of non-white-space characters is counted.
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 1.3.3 of the course notes.
2.
One reason for using an assert statement such as
assert( 0 <= i && i < 10 );
within code is to

is
(b)
(c)
(d)

(a) terminate execution and send an error message whenever the condition
violated
send a warning message but continue execution when the condition is violated
instruct the compiler to set i to any value in the indicated range
provide a comment for the user

Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 1.3.4 of the course notes.
3.
If a user-defined class Complex has overloaded operator+=, then one woul
d expect this operator to have which of the following declarations?
(a) void operator+=( float real, float imag );
(b) void operator+=( const Complex& rhs );
(c) Complex& operator+=( const Complex rhs );
(d) Complex& operator+=( const Complex& rhs );
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 1.3.2 of the course notes.
4.
Which of the following C++ operators is the address-of operator?
(a) &
(b) %
(c) !
(d) *
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 1.4.1 in the course notes.
5.
Which of the following statements is true about a reference used as a function p
arameter?
(a) It cannot be used in a function prototype.
(b) It is not as efficient as using a pointer.
(c) It allows a function to modify the original object passed in as the argument
.
(d) It passes a copy of the object.
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 1.4.2 of the course notes.
6.
How does C++ handle memory allocation?
(a) Allocation and deallocation is the responsibility of the programmer.
(b) C++ has a garbage collector that can be used or turned off.
(c) Allocation and deallocation is completely shielded from the programmer.
(d) C++ always uses a garbage collector.
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 1.4.3 of the course notes.
7.
Consider the following inheritance declarations.
class Base
{ public: int x; private: int y; };
class Derived: public Base { public: int z; };
Derived D;
Under these declarations, which of the following statements, if any, will fail t
o compile?
(a) None
(b) D.z = 555;
(c) D.y = 555;
(d) D.x = 555;
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 1.5.1 of the course notes.
8.
Which of the following is an example of a pure virtual function?
(a) virtual int Compute() = 0;
(b) virtual int Compute() { return 0; };
(c) virtual int Compute();
(d) int Compute() { Compute = 0; };
Correct answer is

(a)

Your score on this question is:


Feedback:

10.00

See section 1.5.2 of the course notes.


9.
Consider the following definitions of a C++ class.
class Array {
public:
typedef float Item;
// <-- change here
Item& operator[](int i) {return arr[i];}
private:
int
len; // length of array
Item *arr; // pointer to first elm
};
template<class T>
class Array {
public:
T& operator[](int i) {return arr[i];}
private:
int len;
T *arr; };
The second definition of class Array is _____ versatile than the first _____ eff
icient at run time when used in a program.
(a) less, and equally
(b) less, but less
(c) more, but less
(d) more, and equally
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 1.5.3 of the course notes.
10.
In C++ exception handling, a try block must be followed by _____ catch block(s).
(a) exactly one
(b) exactly two
(c) one or more
(d) three or fewer
Correct answer is

(c)

Your score on this question is:

10.00

1.
Consider the following C++ program segment, which uses the STL.

stack<int,vector<int> > S;
Execution of the statement results in creation of which of the following?
(a) A stack of integer vectors
(b) A vector of integer stacks
(c) A vector of integers
(d) A stack of integers
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 2.4.2 of the course notes.
2.
In the C++ Standard Template Library (STL), the class queue is _____ that uses _
____ for storage.
(a) an adapter, a
(b) a sequence container,
(c) a sequence container,
(d) an adapter, a C-style
Correct answer is

sequence container
a C-style array
an adapter class
array
(a)

Your score on this question is:

10.00

Feedback:
See Chapter 7, page 249, in the course textbook.
3.
The queue adapter interface in the C++ Standard Template Library contains which
of the following member functions?
1. push
2. pop_back

(a) None
(b) II only
(c) I and II
(d) I only
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 2.4.2 in the course notes.
4.
Which of the following is (are) typically managed using a stack?
1. Implementation of function calls in a procedural programming language
2. Evaluating arithmetic expressions, taking precedence rules into account
3. Handling jobs sent to a printer, and ensuring that the first jobs to be su
bmitted are printed first

(a) I, II, and III


(b) I and II only
(c) I and III only
(d) II only
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See Chapter 7, pages 235C236, in the course textbook.
5.
Which of the following operations typically removes an item from a stack?
(a) empty
(b) pop
(c) top
(d) push
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See Chapter 7, pages 233C234, in the course textbook.
6.
Which of the following linear data structures use a first-in, first-out element
insertion and removal policy?

1. Stacks
2. Queues

(a) I only
(b) None
(c) II only
(d) I and II
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See sections 2.4.1 and 2.5.1 in the course notes.
7.
Execution of the code fragment
list<int> A(10);
does which of the following?
(a)
Creates
Creates
Creates
values.

(b)
(c)
(d)
dom

Creates a linked list of 10 ints, with each element initially 0.


10 linked lists of ints, all initially empty.
an empty linked list of ints, but reserves memory for 10 entries
a linked list of 10 ints, with each element initially containing ran

Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 2.2.3 of the course notes.
8.
Consider the following code fragment, where L is a linked list of integers.
for( it = L.begin(); it != L.end(); ++it )
*it += 10;
Execution of this fragment has the effect of
(a) appending 10 to the list
(b) adding 10 to each list element
(c) inserting a new element 10 after each list element
(d) stepping through the lists in increments of 10
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 2.2.3 of the course notes.
9.
The nodes of a _____ linked list can be traversed _____.
(a) singly, forward and backward
(b) singly, forward only
(c) doubly, forward only
(d) doubly, backward only
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 2.3.1, subsection "Linking Elements Together," in the course notes.
10.
To access an element in a singly linked list, a program must
(a) allocate memory for temporary nodes
(b) compute a hash value for the element
(c) add the element's index to the memory address of the first element in the li
st
(d) traverse all nodes in the list prior to that element
Correct answer is

(d)

Your score on this question is:

10.00

1.
Consider the following C++ program segment, which uses the STL.
stack<int,vector<int> > S;
Execution of the statement results in creation of which of the following?
(a) A stack of integer vectors
(b) A vector of integer stacks
(c) A stack of integers
(d) A vector of integers

Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 2.4.2 of the course notes.
2.
Differences between the STL adapter queue and the STL container deque include wh
ich of the following?
1. queue provides support for iterators, whereas deque does not.
2. queue provides access to only the first and last elements in a collection,
whereas deque permits access to an entire collection.

(a) I and II
(b) II only
(c) None
(d) I only
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 2.4.2 in the course notes.
3.
The queue adapter interface in the C++ Standard Template Library contains which
of the following member functions?
1. push
2. pop_back

(a) None
(b) I and II
(c) II only
(d) I only
Correct answer is

(d)

Your score on this question is:


Feedback:
See section 2.4.2 in the course notes.

10.00

4.
Which of the following statements is (are) true about stacks?
1. Elements are inserted and deleted in last-in-first-out order.
2. Stacks can be implemented using linked lists.
3. Stacks can be implemented using arrays.

(a) II and III only


(b) I and III only
(c) I and II only
(d) I, II, and III
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 2.4.1 of the course notes.
5.
Which of the following is (are) typically managed using a stack?
1. Implementation of function calls in a procedural programming language
2. Evaluating arithmetic expressions, taking precedence rules into account
3. Handling jobs sent to a printer, and ensuring that the first jobs to be su
bmitted are printed first

(a) I, II, and III


(b) I and II only
(c) II only
(d) I and III only
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See Chapter 7, pages 235C236, in the course textbook.
6.
Which of the following linear data structures use a first-in, first-out element
insertion and removal policy?
1. Stacks
2. Queues

(a) I and II
(b) I only
(c) None
(d) II only
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See sections 2.4.1 and 2.5.1 in the course notes.
7.
Consider the following code fragment concerning the STL list class.
list<int> L(10);
L[3] = 555;
The fragment will produce a compile time error because
(a) the class list does not support the bracket operator
(b) the class list only supports the const version of the bracket operator
(c) the class list does not support a constructor with given length
(d) L is an array of 10 list objects, and we cannot assign 555 to a list object
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 2.2.3 of the course notes.
8.
Execution of the code fragment
list<int> A(10);
does which of the following?

(b)
(c)
(d)
dom

(a)
Creates
Creates
Creates
values.

Creates 10 linked lists of ints, all initially empty.


an empty linked list of ints, but reserves memory for 10 entries
a linked list of 10 ints, with each element initially 0.
a linked list of 10 ints, with each element initially containing ran

Correct answer is

(c)

Your score on this question is:


Feedback:

10.00

See section 2.2.3 of the course notes.


9.
Which of the following statements is (are) true about the locations of a linked
list's nodes in memory?
1. Nodes must appear at a fixed distance from one another in memory.
2. The order of elements in a list must match the order of the list's nodes i
n memory.

(a) I and II
(b) None
(c) I only
(d) II only
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 2.3.1, subsection "A Non-Contiguous List," in the course notes.
10.
Which of the following is (are) typically true about linked lists?
1. Objects in a linked list are stored contiguously in memory.
2. All elements in a list are copied to new locations in memory upon frontal
insertions to the list.

(a) I only
(b) II only
(c) None
(d) I and II
Correct answer is

(c)

Your score on this question is:

0.00

1.
What would be the consequences for algorithms if recursion were removed
from C++?
(a) All algorithms could still be implemented, but often less elegantly.
(b) None
(c) Some algorithms could no longer be implemented.
(d) All algorithms could still be implemented, but the efficiency would often be
catastrophically worse.

Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 3.1.1 of the course notes.
2.
Consider the following definition of a recursive function ff in C++.
int ff( int n, int m )
{
if( n == 0 ) return m;
return ff( n - 1, m + 1 );
}
Which of the following characterizes the value returned by the call f(n,m)?
(a) The product of m and n
(b) The greatest common divisor of m and n
(c) The least common multiple of m and n
(d) The sum of m and n
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 3.1.1 of the course notes.
3.
Consider the following definition of a recursive function f.
int f( int x )
{
if( x == 0 ) return 1;
return x * f( x );
}
For which inputs x will the call f(x) terminate?
(a)
(b) For all
(c) For x =
(d) For all

For all odd inputs x only


even inputs x only
0 only
inputs x

Correct answer is

(c)

Your score on this question is:


Feedback:
See section 3.1.1 of the course notes.
4.

10.00

Consider the following definition of a recursive function ff in C++.


int ff( int n, int m )
{
if( n == 0 ) return 0;
return ff( n - 1, m ) + m;
}
Which of the following characterizes the value returned by the call f(n,m)?
(a) The greatest common divisor of m and n
(b) The sum of m and n
(c) The least common multiple of m and n
(d) The product of m and n
Correct answer is

(d)

Your score on this question is:

0.00

Feedback:
See section 3.1.1 of the course notes.
5.
Consider the function defined as follows.
int f( int n )
{
if( n == 0 ) return 0;
if( (n & 1) == 0 ) return f(n/2);
return f(n/2) + 1;
}
The value returned by the call f( 10 ); is
(a) 3
(b) 5
(c) 1
(d) 2
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 3.1.1 of the course notes.
6.
Consider the following definition of a recursive function ff.
int ff( int n )
{
if( n == 0 ) return 1;

return 2 * ff( n - 1 );
}
If n > 0, what is returned by ff( n )?
(a) n2
(b) 2n
(c) 2 * n
(d) log2 n
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 3.1.1 of the course notes.
7.
Which of the following is (are) true of recursive algorithms and the backtrackin
g problem-solving technique?
1. Recursive algorithms implement backtracking by reducing a problem into sma
ller and smaller sub-problems.
2. Recursive algorithms cannot be used to implement backtracking.
3. Recursive algorithms that implement backtracking do not typically have a b
ase case.

(a) II only
(b) None
(c) I only
(d) I and III only
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 3.2.2 in the course notes.
8.
Using a backtracking technique to solve a problem typically involves
(a) starting with the set of all possible solutions and working backward
s from each to determine which is the actual solution
(b) using a breadth-first strategy to search the problem space
(c) pursuing a possible solution until it is found to be a solution or a non-sol
ution
(d) using concurrency to check several possible solutions simultaneously

Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 3.2.2 in the course notes.
9.
What is the runtime overhead of a divide-and-conquer algorithm that recursively
processes two equal halves of a problem that each have an overhead of O(n)?
(a) O(n2)
(b) O(2n)
(c) O(n log n)
(d) O(log n)
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See Chapter 8, page 301, in the course textbook.
10.
Typical divide and conquer algorithms use _____ to divide a problem into smaller
sub-problems. The _____ typically solve(s) these sub-problems directly.
(a) a process scheduler, individual processes
(b) recursive function calls, base case of the recursion
(c) iteration, body of the loop
(d) inheritance, methods of the child class
Correct answer is

(b)

Your score on this question is:

10.00

1.
Which of the following is the main reason for using recursion?
(a) To obtain short, elegant solutions
(b) To improve efficiency
(c) To avoid templates and inheritance
(d) To use less memory
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 3.1.1 of the course notes.
2.
Consider the following definition of a recursive function f.
int f( int x )
{
if( x == 0 ) return 1;
return x * f( x );
}
For which inputs x will the call f(x) terminate?
(a) For all even inputs x only
(b) For x = 0 only
(c) For all odd inputs x only
(d) For all inputs x
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 3.1.1 of the course notes.
3.
How many calls to itself is a recursive function allowed to make?
(a) Any number
(b) At most one
(c) None
(d) At most two
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 3.1.1 of the course notes.
4.
Consider the following definition of a recursive function f.
bool f( int x )
{
if( (x & 1) == 1 ) return (x == 1);
return f( x >> 1 );
// right shift
}
The value returned by the call f(x) will determine whether the input x is

(a) a prime
(b) odd
(c) even
(d) a power of 2
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 3.1.1 of the course notes.
5.
Consider the following definition of a recursive function ff in C++.
int ff( int n, int m )
{
if( n == 0 ) return 0;
return ff( n - 1, m ) + m;
}
Which of the following characterizes the value returned by the call f(n,m)?
(a) The sum of m and n
(b) The product of m and n
(c) The greatest common divisor of m and n
(d) The least common multiple of m and n
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 3.1.1 of the course notes.
6.
Consider the following definition of a recursive function ff in C++.
int ff( int n, int m )
{
if( n == 0 ) return m;
return ff( n - 1, m + 1 );
}
Which of the following characterizes the value returned by the call f(n,m)?
(a) The sum of m and n
(b) The least common multiple of m and n
(c) The greatest common divisor of m and n
(d) The product of m and n
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 3.1.1 of the course notes.
7.
Using a backtracking technique to solve a problem typically involves
(a) using a breadth-first strategy to search the problem space
(b) using concurrency to check several possible solutions simultaneously
(c) starting with the set of all possible solutions and working backwards from e
ach to determine which is the actual solution
(d) pursuing a possible solution until it is found to be a solution or a non-sol
ution
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 3.2.2 in the course notes.
8.
A backtracking algorithm is one that
(a) uses recursion to test all possible solutions for a problem
(b) uses a binary search to solve a problem
(c) splits a problem into two equal halves and uses recursion to solve each half
(d) uses loops to iterate through all possible solutions for a problem
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See Chapter 8, page 308, in the course textbook.
9.
Typical divide and conquer algorithms use _____ to divide a problem into smaller
sub-problems. The _____ typically solve(s) these sub-problems directly.
(a) inheritance, methods of the child class
(b) a process scheduler, individual processes
(c) recursive function calls, base case of the recursion
(d) iteration, body of the loop

Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 3.2.1 in the course notes.
10.
A divide-and-conquer algorithm typically makes use of
(a) recursion
(b) iteration through looping
(c) integer division
(d) floating-point division
Correct answer is

(a)

Your score on this question is:

10.00

1.
Consider the following statement using the STL sort() routine.
sort( A.begin(), A.end(), f );
Which of the following most accurately describes the result of executing this st
atement?
(a) Container A is sorted by applying function f to its elements.
(b) Container A is sorted using the Boolean valued function f for comparisons.
(c) Container A is sorted using sorting algorithm f.
(d) Container A is sorted using the function f for assignments.
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 4.1.3 of the course notes.
2.
Which of the following statements about arrays and linked lists is (are) true in
the context of a sorting algorithm?
1. The sorting algorithm is asymptotically faster if the elements are in an a
rray rather than a linked list.
2. For the algorithm to be implemented, direct element access must be support
ed in both the containers.

(a) I only
(b) None
(c) II only
(d) I and II
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 4.1.2 of the course notes.
3.
Which of the following statements about both arrays and linked lists is (are) tr
ue?
1. Direct element access using subscripts is supported in both the containers
.
2. Both can be searched using binary search.
3. Elements of both the containers can be sorted.

(a) II and III only


(b) II only
(c) I, II, and III
(d) III only
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 4.1.1 of the course notes.
4.
Consider a data set of 100 items. Which of the following is a search algorithm (
are search algorithms) that could possibly examine 25 items in this set before s
ucceeding?
1. Linear search
2. Binary search

(a) I and II
(b) I only
(c) None
(d) II only
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 4.1.1 in the course notes.
5.
Which of the following is true about a good hash function?
(a) It should only output prime numbers.
(b) It should produce apparently random values for given items.
(c) It should produce small outputs for small inputs.
(d) It should never output a prime number.
Correct answer is

(b)

Your score on this question is:

0.00

Feedback:
See section 4.1.3 of the course notes.
6.
Which of the following indicates the primary difficulty with hashing in
general?
(a) Collisions will occur.
(b) Hash tables take up a lot of memory.
(c) Hash functions are hard to compute.
(d) Access in hash tables is slow.
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 4.1.3 of the course notes.
7.
The asymptotic running time of merge sort with an input array of length
n is most closely bound from above by?
(a) O(n2)
(b) O(2n)
(c) O(n)
(d) O(n log n)
Correct answer is

(d)

Your score on this question is:


Feedback:
See section 4.2.1 of the course notes.
8.
Consider the following C++ code fragment.
for( int i = 0; i < n; i += 2 ) {

10.00

for(int j = i; j > 0; j -= 3 ) {
body
}
}
If body executes in constant time, then the asymptotic running time that most cl
osely bounds from above the performance of this code fragment is
(a) O(n log n)
(b) O(n2)
(c) O(n)
(d) O(n3)
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 4.2.1 of the course notes.
9.
Consider the following C++ code fragment.
for( int i = 0; i < n; i++ ) {
for( int j = 0; j < n/5; j++ ) {
body;
}
}
If body executes in constant time, then the asymptotic running time that most cl
osely bounds from above the performance of this code fragment is
(a) O(n)
(b) O(n3)
(c) O(n log n)
(d) O(n2)
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 4.2.1 of the course notes.
10.
Consider the following code fragment.
for( int i = n; i > 0; i /= 2 ) body;
If body executes in O(1) time, then the asymptotic running time that most closel
y bounds the fragment is
(a) O(log n)

(b) O(n)
(c) O(n log n)
(d) O(n2)
Correct answer is

(a)

Your score on this question is:

10.00

1.
Consider the following outline of a template sorting function.
template<class T> void sort( T a[], int n ) { ... }
For a given sorting algorithm S, which of the following is true about using this
outline to implement S?
(a) It is impossible since the algorithm cannot know how to compare two
instances of type T.
(b) It is a reasonable way to implement S.
(c) It is a poor choice since it does not work with linked lists.
(d) It is a poor choice since templates slow down sorting.
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 4.1.3 of the course notes.
2.
Which of the following statements about arrays and linked lists is (are) true in
the context of a sorting algorithm?
1. The sorting algorithm is asymptotically faster if the elements are in an a
rray rather than a linked list.
2. For the algorithm to be implemented, direct element access must be support
ed in both the containers.

(a) I and II
(b) None
(c) II only
(d) I only
Correct answer is

(b)

Your score on this question is:


Feedback:
See section 4.1.2 of the course notes.

10.00

3.
Which of the following statements about both arrays and linked lists is (are) tr
ue?
1. Direct element access using subscripts is supported in both the containers
.
2. Both can be searched using binary search.
3. Elements of both the containers can be sorted.

(a) III only


(b) I, II, and III
(c) II only
(d) II and III only
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 4.1.1 of the course notes.
4.
Which of the following search algorithms can be applied to unsorted data?
1. Linear search
2. Binary search

(a) None
(b) II only
(c) I and II
(d) I only
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 4.1.1 in the course notes.
5.
What is the purpose of using memoizing?
(a) To store return values of functions, in order to avoid recomputation
(b) To eliminate recursion in computing function values
(c) To improve the memory requirements of hash tables
(d) To speed up access in a hash table
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 4.1.4 of the course notes.
6.
Suppose hash() is a hash function. The main idea behind hashing is to us
e a key k to store a value v in which position of a table?
(a) hash(k)
(b) hash(v)
(c) hash() (a random position computed by the hash function using k)
(d) hash(k,v)
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 4.1.3 of the course notes.
7.
Consider the following recursive definition of a function f in C++.
int f(int n)
if( n == 0
return
}
else {
return
}
}

{
) {
1;
f(n / 2);

The asymptotic running time of the call f(n) is most closely bound from above by
(a) O(log n)
(b) O(n)
(c) O(n2)
(d) O(n log n)
Correct answer is

(a)

Your score on this question is:


Feedback:
See section 4.2.1 of the course notes.
8.
Consider the following C++ code fragment.
for( int i = 0; i < n; i += 2 ) {
for( int j = 0; j < n; j += 3 ) {
for( int k = 0; k < n; k += 4 ) {
body;
}

0.00

}
}
If body executes in constant time, then the asymptotic running time that most cl
osely bounds from above the performance of this code fragment is
(a) O(n3)
(b) O(n)
(c) O(n log n)
(d) O(n2)
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 4.2.1 of the course notes.
9.
Consider the following C++ code fragment.
for( int i = 1; i < n; i *= 2 ) body;
If body executes in O(1) time, then the asymptotic running time that most closel
y bounds the code fragment above is
(a) O(n)
(b) O(n2)
(c) O(log n)
(d) O(n log n)
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 4.2.1 of the course notes.
10.
Consider the following C++ code fragment.
for( int i = 0; i < n; i++ ) {
for( int j = 0; j < n; j++ ) {
for( int k = 0; k < n; k++ ) {
body;
}
}
}
If body executes in constant time, then the asymptotic running time that most cl
osely bounds from above the performance of this code fragment is
(a) O(n)

(b) O(n2)
(c) O(2n)
(d) O(n3)
Correct answer is

(d)

Your score on this question is:

10.00

1.
Consider the following outline of a template sorting function.
template<class T> void sort( T a[], int n ) { ... }
For a given sorting algorithm S, which of the following is true about using this
outline to implement S?
(a) It is a reasonable way to implement S.
(b) It is a poor choice since it does not work with linked lists.
(c) It is impossible since the algorithm cannot know how to compare two instance
s of type T.
(d) It is a poor choice since templates slow down sorting.
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 4.1.3 of the course notes.
2.
Which of the following statements is true of the selection-sort algorithm?
1. It is a divide-and-conquer algorithm typically implemented using recursion
.
2. An implementation of the algorithm typically requires the use of a hash ta
ble.

(a) None
(b) II only
(c) I and II
(d) I only
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 4.1.2, subsection "Selection Sort," in the course notes.

3.
In a search over a data set with 1000 items, the maximum number of items examine
d by a linear search is _____, and the maximum number of items examined by a bin
ary search is _____.
(a) 1000, 10
(b) 100, 3
(c) 3, 100
(d) 10, 1000
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 4.1.1 in the course notes.
4.
Which of the following search algorithms can be applied to unsorted data?
1. Linear search
2. Binary search

(a) None
(b) I and II
(c) I only
(d) II only
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 4.1.1 in the course notes.
5.
Which of the following is true about a good hash function?
(a) It should only output prime numbers.
(b) It should never output a prime number.
(c) It should produce apparently random values for given items.
(d) It should produce small outputs for small inputs.
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 4.1.3 of the course notes.
6.
A hash table that stores whether or not a key is present, but does not associate
any other information with the key, is commonly known as
(a) a hash function
(b) a hash map
(c) a hash set
(d) an associative hash table
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 4.1.3 of the course notes.
7.
Consider the following C++ code fragment.
for( int i = 0; i < n; i += 2 ) {
for( int j = 0; j < n; j += 3 ) {
for( int k = 0; k < n; k += 4 ) {
body;
}
}
}
If body executes in constant time, then the asymptotic running time that most cl
osely bounds from above the performance of this code fragment is
(a) O(n2)
(b) O(n3)
(c) O(n log n)
(d) O(n)
Correct answer is

(b)

Your score on this question is:


Feedback:
See section 4.2.1 of the course notes.
8.
Consider the following C++ code fragment.
for( int i = 1; i < n; i *= 2 ) body;

10.00

If body executes in O(1) time, then the asymptotic running time that most closel
y bounds the code fragment above is
(a) O(n2)
(b) O(n)
(c) O(log n)
(d) O(n log n)
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 4.2.1 of the course notes.
9.
Searching for an element in a linked list containing n elements is most closely
bounded from above by
(a) O(n)
(b) O(1)
(c) O(n3)
(d) O(n2)
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 4.2.1 of the course notes.
10.
Consider the following code fragment.
for( int i = n; i > 0; i /= 2 ) body;
If body executes in O(1) time, then the asymptotic running time that most closel
y bounds the fragment is
(a) O(log n)
(b) O(n2)
(c) O(n log n)
(d) O(n)
Correct answer is

(a)

Your score on this question is:

10.00

1.
The main abstractions of the Standard Template Library include which of the foll

owing?
1. Iterators
2. Exception handlers
3. Algorithms

(a) I and III only


(b) III only
(c) I only
(d) I and II only
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 2.1.1, subsection "STL Overview," in the course notes.
2.
Consider the following program segment.
vector<int> A(10);
A.resize(0);
A.push_back(5000);
At the end of an execution of this fragment, the size of vector A is
(a) 0
(b) 10
(c) 1
(d) 5000
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 2.1.2 of the course notes.
3.
Which of the following pointers is (are) stored by nodes in a doubly-linked list
?
1. A pointer to the next node
2. A pointer to the previous node

(a) II only
(b) I only

(c) None
(d) I and II
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 2.3.1, subsection "Linking Elements Together," in the course notes.
4.
Consider the following definition of a recursive function f.
int f( int x )
{
if( x == 0 ) return 1;
return x * f( x - 1 );
}
The inputs for which f will terminate are all x such that x is
(a) odd
(b) even
(c) unrestricted
(d) non-negative
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 3.1.1 of the course notes.
5.
Using a backtracking technique to solve a problem typically involves
(a) using a breadth-first strategy to search the problem space
(b) pursuing a possible solution until it is found to be a solution or a non-sol
ution
(c) starting with the set of all possible solutions and working backwards from e
ach to determine which is the actual solution
(d) using concurrency to check several possible solutions simultaneously
Correct answer is

(b)

Your score on this question is:


Feedback:
See section 3.2.2 in the course notes.

10.00

6.
Which of the following statements is (are) typical of divide and conquer algorit
hms?
1. Recursive function calls are used to divide a problem into smaller and sma
ller sub-problems.
2. Concurrent programming is used to divide the necessary processing between
multiple processors.

(a) I only
(b) None
(c) I and II
(d) II only
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 3.2.1 in the course notes.
7.
Consider the following C++ code fragment.
for( int i = 0; i < n; i++ ) {
for( int j = 0; j < n; j++ ) {
for( int k = 0; k < n; k++ ) {
body;
}
}
}
If body executes in constant time, then the asymptotic running time that most cl
osely bounds from above the performance of this code fragment is
(a) O(n)
(b) O(2n)
(c) O(n2)
(d) O(n3)
Correct answer is

(d)

Your score on this question is:


Feedback:
See section 4.2.1 of the course notes.
8.

10.00

Consider the following outline of a template sorting function.


template<class T> void sort( T a[], int n ) { ... }
For a given sorting algorithm S, which of the following is true about using this
outline to implement S?
(a) It is a reasonable way to implement S.
(b) It is a poor choice since templates slow down sorting.
(c) It is a poor choice since it does not work with linked lists.
(d) It is impossible since the algorithm cannot know how to compare two instance
s of type T.
Correct answer is

(a)

Your score on this question is:

0.00

Feedback:
See section 4.1.3 of the course notes.
9.
In a search over a data set with 1000 items, the maximum number of items examine
d by a linear search is _____, and the maximum number of items examined by a bin
ary search is _____.
(a) 10, 1000
(b) 100, 3
(c) 1000, 10
(d) 3, 100
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 4.1.1 in the course notes.
10.
Which of the following indicates the primary difficulty with hashing in
general?
(a) Hash functions are hard to compute.
(b) Hash tables take up a lot of memory.
(c) Access in hash tables is slow.
(d) Collisions will occur.
Correct answer is

(d)

Your score on this question is:


tiple-Choice Quiz 6

10.00View Assessment Result: Mul

Your performance was as follows:


1.
Time-sharing occurs when

(a) more than one program executes concurrently on a single computer.


(b) there is not enough memory to run all the applications that have been start
ed.
(c) clocks are properly synchronized in a network of computers.
(d) one program must terminate before the next program can run.
Correct answer is

(a)

Your score on this question is: 25.00


Feedback:
See section 6.2.1 of the course notes.
2.
Polling is undesirable in a time-shared operating system because

(a) it leads to interference between two applications accessing the sam


e resource.
(b) it is too complicated to implement
(c) it makes programs much larger.
(d) it wastes time that could be used to do useful work.
Correct answer is

(d)

Your score on this question is: 25.00


Feedback:
See section 6.2.2 of the course notes.
3.
Which of these are properties of threads?
Only processes with special privileges can create threads.
Threads eliminate the need to change address spaces in a context switch.
Threads share memory.

(a) II and III only


(b) II only
(c) I and III only
(d) I, II, and III
Correct answer is

(a)

Your score on this question is: 25.00

Feedback:
See section 6.3.1 of the course notes.
4.
A reentrant function can be entered

(a) at several points, not only the top


(b) concurrently by more than one thread
(c) multiple times but only by one thread at a time
(d) only once before variables are reinitialized
Correct answer is

(b)

Your score on this question is: 25.00


Feedback:
See section 6.3.3 of the course notes.
Go to top of assessment.
Total score: 100.00
? Copyright 2005 iCarnegie, Inc. All rights reserved.
View Assessment Result

1.
How many calls to itself is a recursive function allowed to make?
(a) None
(b) At most two
(c) Any number
(d) At most one
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 3.1.1 of the course notes.
2.
Consider the following definition of a recursive function f.
int f( int x )
{
if( x == 0 ) return 1;
return x * f( x - 1 );
}

The inputs for which f will terminate are all x such that x is
(a) odd
(b) non-negative
(c) even
(d) unrestricted
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 3.1.1 of the course notes.
3.
What would be the consequences for algorithms if recursion were removed
from C++?
(a) Some algorithms could no longer be implemented.
(b) None
(c) All algorithms could still be implemented, but often less elegantly.
(d) All algorithms could still be implemented, but the efficiency would often be
catastrophically worse.
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 3.1.1 of the course notes.
4.
Consider the following definition of a recursive function f.
bool f( int x )
{
if( (x & 1) == 1 ) return (x == 1);
return f( x >> 1 );
// right shift
}
The value returned by the call f(x) will determine whether the input x is
(a) even
(b) a prime
(c) a power of 2
(d) odd
Correct answer is

(c)

Your score on this question is:


Feedback:
See section 3.1.1 of the course notes.
5.

10.00

Consider the function defined as follows.


int f( int n )
{
if( n == 0 ) return 0;
if( (n & 1) == 0 ) return f(n/2);
return f(n/2) + 1;
}
The value returned by the call f( 10 ); is
(a) 3
(b) 2
(c) 1
(d) 5
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 3.1.1 of the course notes.
6.
Consider the following definition of a recursive function f.
int f( int x )
{
if( x == 0 ) return 1;
return x * f( x );
}
For which inputs x will the call f(x) terminate?
(a)
(b) For all
(c) For x =
(d) For all

For all inputs x


odd inputs x only
0 only
even inputs x only

Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 3.1.1 of the course notes.
7.
A backtracking algorithm is one that
(a) splits a problem into two equal halves and uses recursion to solve e
ach half
(b) uses loops to iterate through all possible solutions for a problem

(c) uses recursion to test all possible solutions for a problem


(d) uses a binary search to solve a problem
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See Chapter 8, page 308, in the course textbook.
8.
Which of the following is (are) true of the minimax strategy for deciding the op
timal move in a two-person game?
1. It assumes that a human player will eventually make a mistake by playing a
move that is not optimal.
2. It is commonly used with a backtracking algorithm.

(a) None
(b) I and II
(c) II only
(d) I only
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See Chapter 8, pages 308C310, in the course textbook.

10.
Typical divide and conquer algorithms use _____ to divide a problem into smaller
sub-problems. The _____ typically solve(s) these sub-problems directly.
(a) recursive function calls, base case of the recursion
(b) inheritance, methods of the child class
(c) a process scheduler, individual processes
(d) iteration, body of the loop
Correct answer is

(a)

Your score on this question is:


Feedback:

10.00

See section 3.2.1 in the course notes.


Go to top of assessment.
Total score: 90.00
? Copyright 2004 iCarnegie, Inc. All rights reserved.

1.
Consider the following definition of a recursive function f.
int f( int x )
{
if( x == 0 ) return 1;
return x * f( x - 1 );
}
The inputs for which f will terminate are all x such that x is
(a) non-negative
(b) unrestricted
(c) odd
(d) even
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 3.1.1 of the course notes.
2.
How many calls to itself is a recursive function allowed to make?
(a) None
(b) Any number
(c) At most two
(d) At most one
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 3.1.1 of the course notes.
3.
Consider the following definition of a recursive function ff in C++.
int ff( int n, int m )

{
if( n == 0 ) return m;
return ff( n - 1, m + 1 );
}
Which of the following characterizes the value returned by the call f(n,m)?
(a) The least common multiple of m and n
(b) The sum of m and n
(c) The product of m and n
(d) The greatest common divisor of m and n
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 3.1.1 of the course notes.
4.
Which of the following is the main reason for using recursion?
(a) To obtain short, elegant solutions
(b) To improve efficiency
(c) To avoid templates and inheritance
(d) To use less memory
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 3.1.1 of the course notes.
5.
Consider the following definition of a recursive function ff.
int ff( int n )
{
if( n == 0 ) return 1;
return 2 * ff( n - 1 );
}
If n > 0, what is returned by ff( n )?
(a) 2n
(b) log2 n
(c) n2
(d) 2 * n
Correct answer is

(a)

Your score on this question is:


Feedback:
See section 3.1.1 of the course notes.

10.00

6.
Consider the following definition of a recursive function f.
int f( int x )
{
if( x == 0 ) return 1;
return x * f( x );
}
For which inputs x will the call f(x) terminate?
(a) For x = 0 only
(b) For all odd inputs x only
(c) For all even inputs x only
(d) For all inputs x
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 3.1.1 of the course notes.
7.
Using a backtracking technique to solve a problem typically involves
(a) using concurrency to check several possible solutions simultaneously
(b) starting with the set of all possible solutions and working backwards from e
ach to determine which is the actual solution
(c) pursuing a possible solution until it is found to be a solution or a non-sol
ution
(d) using a breadth-first strategy to search the problem space
Correct answer is

(c)

Your score on this question is:

10.00

Feedback:
See section 3.2.2 in the course notes.
8.
Which of the following is (are) true of the minimax strategy for deciding the op
timal move in a two-person game?
1. It assumes that a human player will eventually make a mistake by playing a
move that is not optimal.
2. It is commonly used with a backtracking algorithm.

(a) II only
(b) I only
(c) I and II
(d) None
Correct answer is

(a)

Your score on this question is:

0.00

Feedback:
See Chapter 8, pages 308C310, in the course textbook.
9.
Typical divide and conquer algorithms use _____ to divide a problem into smaller
sub-problems. The _____ typically solve(s) these sub-problems directly.
(a) a process scheduler, individual processes
(b) recursive function calls, base case of the recursion
(c) inheritance, methods of the child class
(d) iteration, body of the loop
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 3.2.1 in the course notes.
10.
Consider the following C++ function that uses a divide and conquer approach to c
alculate the sum of a range of numbers.
int sum(int i, int j) {
if (i == j) {
return i;
}
else {
int mid = (i+j) / 2;
int result = sum(i,mid) + sum(mid+1,j);
return result;
}
}
Which of the following lines of code from the above function divides this proble
m into sub-problems?

(a) return result;


(b) int result = sum(i,mid) + sum(mid+1,j);
(c) int mid = (i+j) / 2;
(d) if (i == j) {
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 3.2.1 in the course notes.
Go to top of assessment.
Total score: 90.00
? Copyright 2004 iCarnegie, Inc. All rights reserved.
Your performance was as follows:
You took 22 minutes on this assessment from Sat Nov 26 2005 16:30:46 GMT
+0800 to Sat Nov 26 2005 16:52:39 GMT+0800.
Total score: 50.00

1.
Which of the following is the main reason for using recursion?
(a) To use less memory
(b) To avoid templates and inheritance
(c) To obtain short, elegant solutions
(d) To improve efficiency
Correct answer is

(c)

Your score on this question is:

0.00

Feedback:
See section 3.1.1 of the course notes.
2.
Consider the following definition of a recursive function f.
int f( int x )
{
if( x == 0 ) return 1;
return x * f( x );
}
For which inputs x will the call f(x) terminate?

(a) For all odd inputs x only


(b) For all even inputs x only
(c) For all inputs x
(d) For x = 0 only
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 3.1.1 of the course notes.
3.
Consider the following definition of a recursive function f.
bool f( int x )
{
if( (x & 1) == 1 ) return (x == 1);
return f( x >> 1 );
// right shift
}
The value returned by the call f(x) will determine whether the input x is
(a) odd
(b) a prime
(c) a power of 2
(d) even
Correct answer is

(c)

Your score on this question is:

0.00

Feedback:
See section 3.1.1 of the course notes.
4.
Consider the following definition of a recursive function f.
int f( int x )
{
if( x == 0 ) return 1;
return x * f( x - 1 );
}
The inputs for which f will terminate are all x such that x is
(a) non-negative
(b) unrestricted
(c) odd
(d) even
Correct answer is

(a)

Your score on this question is:

10.00

Feedback:
See section 3.1.1 of the course notes.
5.
Consider the following definition of a recursive function ff in C++.
int ff( int n, int m )
{
if( n == 0 ) return m;
return ff( n - 1, m + 1 );
}
Which of the following characterizes the value returned by the call f(n,m)?
(a) The least common multiple of m and n
(b) The sum of m and n
(c) The product of m and n
(d) The greatest common divisor of m and n
Correct answer is

(b)

Your score on this question is:

10.00

Feedback:
See section 3.1.1 of the course notes.
6.
Consider the function defined as follows.
int f( int n )
{
if( n == 0 ) return 0;
if( (n & 1) == 0 ) return f(n/2);
return f(n/2) + 1;
}
The value returned by the call f( 10 ); is
(a) 3
(b) 2
(c) 5
(d) 1
Correct answer is

(b)

Your score on this question is:


Feedback:
See section 3.1.1 of the course notes.
7.

10.00

Which of the following is (are) true of recursive algorithms and the backtrackin
g problem-solving technique?
1. Recursive algorithms implement backtracking by reducing a problem into sma
ller and smaller sub-problems.
2. Recursive algorithms cannot be used to implement backtracking.
3. Recursive algorithms that implement backtracking do not typically have a b
ase case.

(a) None
(b) I and III only
(c) II only
(d) I only
Correct answer is

(d)

Your score on this question is:

10.00

Feedback:
See section 3.2.2 in the course notes.
8.
Using a backtracking technique to solve a problem typically involves
(a) pursuing a possible solution until it is found to be a solution or a
non-solution
(b) using a breadth-first strategy to search the problem space
(c) using concurrency to check several possible solutions simultaneously
(d) starting with the set of all possible solutions and working backwards from e
ach to determine which is the actual solution
Correct answer is

(a)

Your score on this question is:

0.00

Feedback:
See section 3.2.2 in the course notes.
9.
Which of the following statements is (are) typical of divide and conquer algorit
hms?
1. Recursive function calls are used to divide a problem into smaller and sma
ller sub-problems.
2. Concurrent programming is used to divide the necessary processing between

multiple processors.

(a) None
(b) I and II
(c) I only
(d) II only
Correct answer is

(c)

Your score on this question is:

0.00

Feedback:
See section 3.2.1 in the course notes.

Go to top of assessment.
Total score: 50.00
? Copyright 2004 iCarnegie, Inc. All rights reserved.
View Assessment Result: Multiple-Choice Quiz 4

Your performance was as follows:


1.
In C and C++, which of the following functions allocate memory from the
heap?
printf()
creating a new Standard Template Library string
cout << "Hello World"

(a) II only.
(b) I only.
(c) I and II only.
(d) II and III only.
Correct answer is

(c)

Your score on this question is: 25.00


Feedback:
See section 4.3.1 of the course notes.
2.
Which of the following approaches towards optimizing programs is most ad

visable?

(a) Optimize after all functions are written and debugged.


(b) Optimize the more complex functions first.
(c) Optimize main() first.
(d) "Optimize as you go": make sure every function is optimized before writing
the next one.
Correct answer is

(a)

Your score on this question is: 25.00


Feedback:
See section 4.1.1 of the course notes.
3.
Which of the following are advantages of using statistical sampling to p
rofile programs?
Exact run times of all functions can be determined.
Code can be instrumented automatically.
The performance impact due to measurement can be minimal.

(a) I, II, and III


(b) I and II only
(c) I and III only
(d) II and III only
Correct answer is

(d)

Your score on this question is: 25.00


Feedback:
See section 4.1.2 of the course notes.
4.
Which of the following is likely to offer the best performance improveme
nt for programs that spend 50% of their time comparing strings?

(a) Be sure to use hardware string-comparison instructions.


(b) Call a library function for string comparison.
(c) Write in-line code for string comparison to eliminate a procedure call.
(d) Store strings uniquely so that pointer comparison can be used.
Correct answer is

(d)

Your score on this question is: 25.00


Feedback:
See section 4.2.2 of the course notes.
Go to top of assessment.

Total score: 100.00


? Copyright 2005 iCarnegie, Inc. All rights reserved.
View Assessment Result: Multiple-Choice Quiz 3

Your performance was as follows:


1.
The key feature of implicit memory management is that memory is freed au
tomatically. Which of the following features of C make(s) it difficult to add su
pport for implicit memory management in C?
Pointers are not always initialized.
Type casting makes it impossible to know when a value could be a pointer.
C programs can allocate memory at runtime.

(a) I and II only


(b) II only
(c) III only
(d) I only
Correct answer is

(a)

Your score on this question is: 16.67


Feedback:
See section 3.1.2 of the course notes.
2.
Which of the following are true about statically allocated data in C pro
grams?
Its location is chosen by the compiler.
Its location may change during execution if more memory is required.
Its location is not known directly but can be found in a static symbol table.

(a) I and II only.


(b) III only.
(c) II and III only.
(d) I only.
Correct answer is

(d)

Your score on this question is: 0.00


Feedback:
See section 3.1.1 of the course notes.
3.
What is the value of an uninitialized pointer variable declared within a

function?

(a) its last value from the previous call to the function
(b) 0 (or NULL)
(c) 0xDEADBEEF
(d) the value is undefined
Correct answer is

(d)

Your score on this question is: 0.00


Feedback:
See section 3.3.2 of the course notes.
4.
The unary & operator returns

(a) the contents of memory at a given address.


(b) the logical "and" of two integer operands.
(c) the operand unaltered.
(d) the address of a data object.
Correct answer is

(d)

Your score on this question is: 0.00


Feedback:
See section 3.3.1 of the course notes.
5.
The C expression a->b is equivalent to

(a) (*a).b
(b) (&a).b
(c) (&a) + b
(d) *(a + b)
Correct answer is

(a)

Your score on this question is: 16.67


Feedback:
See section 3.3.1 of the course notes.
6.
In C, calloc() differs from malloc() in that calloc()

(a) detects memory allocation errors.


(b) allocates additional memory from the stack.

(c) is faster.
(d) sets the contents of the block to zero before returning.
Correct answer is

(d)

Your score on this question is: 16.67


Feedback:
See section 3.3.2 of the course notes.
Go to top of assessment.
Total score: 50.00
? Copyright 2005 iCarnegie, Inc. All rights reserved.
View Assessment Result

Family Name: Han


Given Name: Lian
Login: nwpu043814
E-mail: october3rd@sina.com
Status: Enrolled
Assessment Name: Multiple-Choice Quiz 1
Instance: 1
Section: NWPU-SSD6-6
During: Fall 2006
Section Status: Active
For course: System-Level Programming
(SSD6)
Corresponding to: SSD6
At: Software College of Northwestern Polytechnical University
--------------------------------------------------------------------------------

Your performance was as follows:


You took 37 minutes on this assessment from Wed Sep 27 10:30:09 UTC+0800 2006 t
o Wed Sep 27 11:06:20 UTC+0800 2006.
Total score: 85.71

1.

Which of the following is able to describe a computation at the highest level o


f abstraction?
(a) machine code
(b) logic Gates
(c) C++ code
(d) C code
Correct answer is (c)
Your score on this question is: 7.14
Feedback:
See section 1.1.2 of the course notes.

-------------------------------------------------------------------------------2.
Consider the following fragment of C++ source code.
String msg; unsigned int x; int y;
cin >> msg >> x >> y;
cout << x + y;
Which of the following is (are) true regarding execution of the segment?
The input statement will always take the same amount of time to execute.
The output statement will always be executed immediately after the input stateme
nt.
If x and y are both positive, an integer greater than both will be printed.

(a) II only
(b) II and III only
(c) I and II only
(d) none
Correct answer is (d)
Your score on this question is: 7.14
Feedback:
See section 1.1.1 of the course notes.
-------------------------------------------------------------------------------3.
Which of the following must be true if a program is stopped at a specific line
within the Visual C++ debugger?
There is at least one breakpoint enabled.
There is a breakpoint enabled on that line.
There is a breakpoint enabled on the line preceding that line.

(a) I only

(b) none
(c) I and III only
(d) I and II only
Correct answer is (b)
Your score on this question is: 7.14
Feedback:
See section 1.2.2 of the course notes.
-------------------------------------------------------------------------------4.
When using a debugger to find the cause of a program's incorrect behavior,
(a) the faulty code fragment must first be identified
(b) it is fastest to start by stopping the debugger long before the behavior ap
pears
(c) it is often necessary to start the program multiple times under the debugge
r
(d) the program is usually executed to the point at which the behavior occurs a
nd then executed backwards to find the cause
Correct answer is (c)
Your score on this question is: 7.14
Feedback:
See section 1.2.4 of the course notes.
-------------------------------------------------------------------------------5.
Consider the following function.
int factorial(int n) {
if (n == 1) return n;
return n * factorial(n - 1);
}
How many activation records are "popped" when it is invoked by the expression fa
ctorial(4)?
(a) 1
(b) 5
(c) 0
(d) 4
Correct answer is (d)
Your score on this question is: 7.14
Feedback:
See section 1.4.2 of the course notes.

-------------------------------------------------------------------------------6.
Consider the following program.
int i;
int j = 1;
int callee(int number) {
int plusone;
plusone = number + 1;
return plusone;
}
int main (int argc, char *argv[]) {
if (j == 1) return callee(i);
return j;
}
Which of the following are allocated in the activation record immediately after
the function callee() is invoked?
(a) plusone and number only.
(b) i only.
(c) i, j and number only.
(d) plusone only.
Correct answer is (a)
Your score on this question is: 0.00
Feedback:
See section 1.4.2 of the course notes.
-------------------------------------------------------------------------------7.
Consider the program given below.
#include
int callee(void) {
int count = 5;
printf("%d ", (int) &count);
return count;
}
int main (int argc, char *argv[]) {
int count = 4;
count = callee();
printf("%d ", (int) &count);
return 0;
}
Which of the following describes the output of the program?
(a) 5 and 4 are printed, in that order on the same line.
(b) Two different integers are printed, and the value of neither can be determi
ned from the information given.
(c) 5 is printed twice on the same line.
(d) One integer is printed twice, and its value cannot be determined from the i
nformation given.
Correct answer is (b)

Your score on this question is: 7.14


Feedback:
See section 1.4.1 of the course notes.
-------------------------------------------------------------------------------8.
Consider the following program.
int i;
int * jp = &i;
int main(int i, char * argv[]) {
printf("%d %d\n", (int) &i, (int) jp);
}
Which of the following describes what it prints?
(a) nothing: it will not compile because it is ambiguous
(b) two integers that are exactly the same
(c) two very different integers
(d) two values, one 4 greater than the other
Correct answer is (c)
Your score on this question is: 0.00
Feedback:
See section 1.4.1 of the course notes.
-------------------------------------------------------------------------------9.
The Visual C++ Memory window displays
(a) the names and values of variables in memory, interpreted as 32-bit integer
s no matter what the variables' types
(b) the names and values of variables in memory, interpreted in one of several
ways
(c) the contents of memory, interpreted in one of several ways, without the ass
ociated variable names
(d) the contents of memory, interpreted as 32-bit integers, without the associa
ted variable names
Correct answer is (c)
Your score on this question is: 7.14
Feedback:
See section 1.3.3 of the course notes.
-------------------------------------------------------------------------------10.
In a computer in which both addresses and integers are 32 bits wide, how many b

ytes of memory will the compiler allocate for following code fragment?
int a;
int * b = &a;

(a) 4
(b) 0
(c) 32
(d) 8
Correct answer is (d)
Your score on this question is: 7.14
Feedback:
See section 1.3.2 of the course notes.
-------------------------------------------------------------------------------11.
The program counter contains
(a) the number of times a program has been executed
(b) the number of CPU instructions a program has executed so far
(c) the amount of memory a program is currently using
(d) the address of the CPU instruction that is about to be executed
Correct answer is (d)
Your score on this question is: 7.14
Feedback:
See section 1.5.2 of the course notes.
-------------------------------------------------------------------------------12.
A CPU register is a word of CPU memory that
(a) houses a critical variable for the duration of the execution of a program
(b) is automatically loaded when a CPU instruction refers to a word of normal m
emory
(c) records the results of periodic CPU diagnostics
(d) is explicitly loaded and unloaded from normal memory by compiler-generated
instructions
Correct answer is (d)
Your score on this question is: 7.14
Feedback:
See section 1.5.3 of the course notes.

-------------------------------------------------------------------------------13.
We want the variable factorialfunc to hold the address of the first instruction
of the following function:
int factorial(int n) {
if (n == 1) return n;
return n * factorial(n -1);
}
How would we declare the variable?
(a) int (*factorialfunc)(int);
(b) factorial() * factorialfunc;
(c) we can't: C cannot extract the addresses of instructions.
(d) int (int) * factorialfunc
Correct answer is (a)
Your score on this question is: 7.14
Feedback:
See section 1.5.2 of the course notes.
-------------------------------------------------------------------------------14.
Which of the following
chine code generated by
The resulting code will
The resulting code will
The resulting code will

are true of the effect that optimizations have on the ma


compilers?
be faster and/or smaller.
be clearer.
be harder to debug.

(a) I, II, and III


(b) I only
(c) I and II only
(d) I and III only
Correct answer is (d)
Your score on this question is: 7.14
Feedback:
See section 1.5.3 of the course notes.
-------------------------------------------------------------------------------Go to top of assessment.
Total score: 85.71
? Copyright 2005 iCarnegie, Inc. All rights reserved.
View Assessment Result

Family Name: Han


Given Name: Lian
Login: nwpu043814
E-mail: october3rd@sina.com
Status: Active
Assessment Name: Multiple-Choice Quiz 1
Instance: 1
Section: NWPU-SSD6-2
During: Fall 2007
Section Status: Enrolled
For course: System-Level Programming
(SSD6)
Corresponding to: SSD6
At: Software College of Northwestern Polytechnical University
--------------------------------------------------------------------------------

Your performance was as follows:


You took 12 minutes on this assessment from Thu Apr 7 16:30:22 UTC+0800 2007 to
Thu Apr 7 16:41:41 UTC+0800 2007.
Total score: 100.00

1.
Compared to a sequence of machine code instructions, a fragment of C code
(a) does not engage any transistors during its execution
(b) is the native way to program most computers
(c) describes the actions of the computer, not just of the CPU
(d) may describe the same algorithm
Correct answer is (d)
Your score on this question is: 20.00
Feedback:
See section 1.1.2 of the course notes.

--------------------------------------------------------------------------------

2.
Which of the following is able to describe a computation at the highest level o
f abstraction?
(a) C++ code
(b) logic Gates
(c) machine code
(d) C code
Correct answer is (a)
Your score on this question is: 20.00
Feedback:
See section 1.1.2 of the course notes.
-------------------------------------------------------------------------------3.
Which of the following does a debugger do?
Analyze the source code to find programming errors.
Decode machine code generated by a compiler.
Stop execution of a program.

(a) III only


(b) I and III only
(c) I, II, and III.
(d) II and III only
Correct answer is (d)
Your score on this question is: 20.00
Feedback:
See section 1.1.3 of the course notes.
-------------------------------------------------------------------------------4.
Integrated programming environments make it difficult to mix and match tools fr
om different sources. This is
(a) good, because tools from different sources cannot be made to interact with
each other
(b) good, because it ensures compilation is not done incrementally by accident
(c) bad, because all the tools will then have the same user interface
(d) bad, because no single vendor is likely to be the source of all the best to
ols
Correct answer is (d)
Your score on this question is: 20.00
Feedback:

See section 1.1.4 of the course notes.


-------------------------------------------------------------------------------5.
Consider the following fragment of C++ source code.
String msg; unsigned int x; int y;
cin >> msg >> x >> y;
cout << x + y;
Which of the following is (are) true regarding execution of the segment?
The input statement will always take the same amount of time to execute.
The output statement will always be executed immediately after the input stateme
nt.
If x and y are both positive, an integer greater than both will be printed.

(a) II only
(b) II and III only
(c) I and II only
(d) none
Correct answer is (d)
Your score on this question is: 20.00
Feedback:
See section 1.1.1 of the course notes.
-------------------------------------------------------------------------------Go to top of assessment.
Total score: 100.00
? Copyright 2002 iCarnegie, Inc. All rights reserved.
View Assessment Result

Family Name: Han


Given Name: Lian
Login: nwpu043814
E-mail: october3rd@sina.com
Status: Active
Assessment Name: Multiple-Choice Quiz 2
Instance: 1
Section: NWPU-SSD6-2
During: Fall 2007
Section Status: Enrolled
For course: System-Level Programming
(SSD6)

Corresponding to: SSD6


At: Software College of Northwestern Polytechnical University
--------------------------------------------------------------------------------

Your performance was as follows:


You took 7 minutes on this assessment from Thu Apr 14 17:34:02 UTC+0800 2007 to
Thu Apr 14 17:40:08 UTC+0800 2007.
Total score: 40.00

1.
Within Visual C++, which of the following will reveal the value of a variable w
hen the program is stopped at a breakpoint?
Placing the mouse pointer over the variable name in the source file window.
Inserting a printf() in the program.
Typing the variable name on the "Watch" window.

(a) I and III only


(b) III only
(c) II and III only
(d) I, II, and III
Correct answer is (a)
Your score on this question is: 20.00
Feedback:
See section 1.2.3 of the course notes.

-------------------------------------------------------------------------------2.
When debugging using Visual C++, which of the following are possible through th
e Watch window?
The program's execution can be stopped.
The value of an arbitrary C expression can be calculated.
The value of a program variable can be set.

(a) III only


(b) II only
(c) I, II, and III.
(d) II and III only

Correct answer is (d)


Your score on this question is: 0.00
Feedback:
See section 1.2.3 of the course notes.
-------------------------------------------------------------------------------3.
When using a debugger to find the cause of a program's incorrect behavior,
(a) it is often necessary to start the program multiple times under the debugg
er
(b) it is fastest to start by stopping the debugger long before the behavior ap
pears
(c) the program is usually executed to the point at which the behavior occurs a
nd then executed backwards to find the cause
(d) the faulty code fragment must first be identified
Correct answer is (a)
Your score on this question is: 0.00
Feedback:
See section 1.2.4 of the course notes.
-------------------------------------------------------------------------------4.
Which of the following must be true if a program is stopped at a specific line
within the Visual C++ debugger?
There is at least one breakpoint enabled.
There is a breakpoint enabled on that line.
There is a breakpoint enabled on the line preceding that line.

(a) I and III only


(b) I and II only
(c) none
(d) I only
Correct answer is (c)
Your score on this question is: 0.00
Feedback:
See section 1.2.2 of the course notes.
-------------------------------------------------------------------------------5.
In Visual C++, a Win32 Console Application is

(a) a program that is able to control the operating system of a windows comput
er
(b) the status window of the Visual C++ environment
(c) built by using sophisticated "Application Wizards"
(d) the simplest type of application Visual C++ can generate
Correct answer is (d)
Your score on this question is: 20.00
Feedback:
See section 1.2.1 of the course notes.
-------------------------------------------------------------------------------Go to top of assessment.
Total score: 40.00
? Copyright 2002 iCarnegie, Inc. All rights reserved.
View Assessment Result

Family Name: Han


Given Name: Lian
Login: nwpu043814
E-mail: october3rd@sina.com
Status: Active
Assessment Name: Multiple-Choice Quiz 2
Instance: 2
Section: NWPU-SSD6-2
During: Fall 2007
Section Status: Enrolled
For course: System-Level Programming
(SSD6)
Corresponding to: SSD6
At: Software College of Northwestern Polytechnical University
--------------------------------------------------------------------------------

Your performance was as follows:


You took 3 minutes on this assessment from Thu Apr 14 17:41:17 UTC+0800 2007 to
Thu Apr 14 17:43:25 UTC+0800 2007.
Total score: 100.00

1.
Within Visual C++, which of the following will reveal the value of a variable w
hen the program is stopped at a breakpoint?
Placing the mouse pointer over the variable name in the source file window.
Inserting a printf() in the program.
Typing the variable name on the "Watch" window.

(a) III only


(b) I, II, and III
(c) I and III only
(d) II and III only
Correct answer is (c)
Your score on this question is: 20.00
Feedback:
See section 1.2.3 of the course notes.

-------------------------------------------------------------------------------2.
When debugging using Visual C++, which of the following are possible through th
e Watch window?
The program's execution can be stopped.
The value of an arbitrary C expression can be calculated.
The value of a program variable can be set.

(a) I, II, and III.


(b) III only
(c) II and III only
(d) II only
Correct answer is (c)
Your score on this question is: 20.00
Feedback:
See section 1.2.3 of the course notes.
-------------------------------------------------------------------------------3.
When using a debugger to find the cause of a program's incorrect behavior,
(a) the faulty code fragment must first be identified
(b) it is often necessary to start the program multiple times under the debugge
r
(c) the program is usually executed to the point at which the behavior occurs a

nd then executed backwards to find the cause


(d) it is fastest to start by stopping the debugger long before the behavior ap
pears
Correct answer is (b)
Your score on this question is: 20.00
Feedback:
See section 1.2.4 of the course notes.
-------------------------------------------------------------------------------4.
Which of the following must be true if a program is stopped at a specific line
within the Visual C++ debugger?
There is at least one breakpoint enabled.
There is a breakpoint enabled on that line.
There is a breakpoint enabled on the line preceding that line.

(a) I only
(b) none
(c) I and III only
(d) I and II only
Correct answer is (b)
Your score on this question is: 20.00
Feedback:
See section 1.2.2 of the course notes.
-------------------------------------------------------------------------------5.
Which of the following may a Visual C++ Project contain?
icons and HTML pages
a C source file
a flow chart

(a) I and II only


(b) II only
(c) III only
(d) I, II and III
Correct answer is (a)
Your score on this question is: 20.00
Feedback:
See section 1.2.1 of the course notes.
--------------------------------------------------------------------------------

Go to top of assessment.
Total score: 100.00
? Copyright 2002 iCarnegie, Inc. All rights reserved.
View Assessment Result

Family Name: Han


Given Name: Lian
Login: nwpu043814
E-mail: october3rd@sina.com
Status: Active
Assessment Name: Multiple-Choice Quiz 3
Instance: 1
Section: NWPU-SSD6-2
During: Fall 2007
Section Status: Enrolled
For course: System-Level Programming
(SSD6)
Corresponding to: SSD6
At: Software College of Northwestern Polytechnical University
--------------------------------------------------------------------------------

Your performance was as follows:


You took 8 minutes on this assessment from Thu Apr 21 15:12:02 UTC+0800 2007 to
Thu Apr 21 15:19:31 UTC+0800 2007.
Total score: 66.67

1.
The Visual C++ Memory window displays
(a) the contents of memory, interpreted in one of several ways, without the as
sociated variable names
(b) the contents of memory, interpreted as 32-bit integers, without the associa
ted variable names
(c) the names and values of variables in memory, interpreted in one of several
ways
(d) the names and values of variables in memory, interpreted as 32-bit integers
no matter what the variables' types

Correct answer is (a)


Your score on this question is: 0.00
Feedback:
See section 1.3.3 of the course notes.

-------------------------------------------------------------------------------2.
Consider the following code fragment.
int a;
int b;
int main(int argc, char *argv[]) {
int c;
int d;
...
/* some code */
}
Which of the following must be true?
(a) The values of *a and *b are closer to each other than the values of *c and
*d.
(b) The value of &d is closer to the value of &c than to the value of &a.
(c) The value of *d is closer to the value of *c than to the value of *a.
(d) The values of &a and &b are closer to each other than the values of &c and
&d.
Correct answer is (b)
Your score on this question is: 33.33
Feedback:
See section 1.3.1 of the course notes.
-------------------------------------------------------------------------------3.
Consider the following segment of a C program.
int i = 99;
int a[100];
i = a[i + 1];
Which of the following is true of the segment, assuming that Microsoft Visual C+
+ is used as the compiler?
(a) When executed, the program will be prematurely terminated by the operating
system because of an illegal memory access.
(b) Execution will fail because a has the wrong size.
(c) i will have the value 99 at the end of any execution of the segment.
(d) i will have the value of the last element of the array a at the end of any
execution of the segment.

Correct answer is (c)


Your score on this question is: 33.33
Feedback:
See section 1.3.5 of the course notes.
-------------------------------------------------------------------------------Go to top of assessment.
Total score: 66.67
? Copyright 2002 iCarnegie, Inc. All rights reserved.
View Assessment Result

Family Name: Han


Given Name: Lian
Login: nwpu043814
E-mail: october3rd@sina.com
Status: Active
Assessment Name: Multiple-Choice Quiz 3
Instance: 2
Section: NWPU-SSD6-2
During: Fall 2007
Section Status: Enrolled
For course: System-Level Programming
(SSD6)
Corresponding to: SSD6
At: Software College of Northwestern Polytechnical University
--------------------------------------------------------------------------------

Your performance was as follows:


You took 7 minutes on this assessment from Thu Apr 21 15:19:57 UTC+0800 2007 to
Thu Apr 21 15:26:22 UTC+0800 2007.
Total score: 33.33

1.
In one computer, the bytes with addresses A, A+1, A+2 and A+3 contain the integ
er 256, and the variable declared with int * a; has the value A. In a different
computer, the bytes with addresses B, B+1, B+2 and B+3 also contain the integer

256, and the variable declared with int * b has the value B. Which of the follow
ing are necessarily true?
The contents of A+1 are equal to the contents of B+1.
The contents of A+1 are equal to the contents of B+2.
*a == *b

(a) II and III only


(b) I only
(c) I and III only
(d) III only
Correct answer is (d)
Your score on this question is: 0.00
Feedback:
See section 1.3.3 of the course notes.

-------------------------------------------------------------------------------2.
Consider the following code fragment.
int a;
int b;
int main(int argc, char *argv[]) {
int c;
int d;
...
/* some code */
}
Which of the following must be true?
(a) The values of &a and &b are closer to each other than the values of &c and
&d.
(b) The value of &d is closer to the value of &c than to the value of &a.
(c) The values of *a and *b are closer to each other than the values of *c and
*d.
(d) The value of *d is closer to the value of *c than to the value of *a.
Correct answer is (b)
Your score on this question is: 33.33
Feedback:
See section 1.3.1 of the course notes.
-------------------------------------------------------------------------------3.
Consider the following code.
char a[100];
a[99] = *((char *) (((int) &a[0]) + 4))

If integers are 32 bits wide, which of the following values is equal to a[99]?
(a) a[0] + 4
(b) a[3]
(c) the integer stored in the bytes a[4], a[5], a[6] and a[7]
(d) a[4]
Correct answer is (d)
Your score on this question is: 0.00
Feedback:
See section 1.3.5 of the course notes.
-------------------------------------------------------------------------------Go to top of assessment.
Total score: 33.33
? Copyright 2002 iCarnegie, Inc. All rights reserved.
View Assessment Result

Family Name: Han


Given Name: Lian
Login: nwpu043814
E-mail: october3rd@sina.com
Status: Active
Assessment Name: Multiple-Choice Quiz 4
Instance: 1
Section: NWPU-SSD6-2
During: Fall 2007
Section Status: Enrolled
For course: System-Level Programming
(SSD6)
Corresponding to: SSD6
At: Software College of Northwestern Polytechnical University
--------------------------------------------------------------------------------

Your performance was as follows:


You took 10 minutes on this assessment from Thu May 19 17:42:58 UTC+0800 2007 t
o Thu May 19 17:52:58 UTC+0800 2007.
Total score: 80.00

1.
What does the following program print?
void callee(int * count) {
count++;
}
int main (int argc, char *argv[]) {
int count = 4;
callee(&count);
printf("%d", count);
return 0;
}

(a) 8
(b) cannot be determined from the information given.
(c) 5
(d) 4
Correct answer is (d)
Your score on this question is: 20.00
Feedback:
See section 1.4.1 of the course notes.

-------------------------------------------------------------------------------2.
Consider the following program.
int square(int * arg) {
int n = * arg;
return n * n;
}
int main (int argc, char * argv[]) {
int arg = strtol(argv[1], NULL, 0);
return square(arg);
}
When it is executed with the argument 5, the variable n is allocated to
(a) exactly one address not known to the compiler.
(b) many addresses chosen by the compiler.
(c) exactly one address chosen by the compiler.
(d) many addresses neither of which are known to the compiler.
Correct answer is (a)
Your score on this question is: 20.00

Feedback:
See section 1.4.1 of the course notes.
-------------------------------------------------------------------------------3.
What does the following program print?
int callee(int * count) {
count++;
return *count;
}
int main (int argc, char *argv[]) {
int count = 4;
int retval;
retval = callee(&count);
printf("%d", retval);
return 0;
}

(a) 8
(b) 5
(c) cannot be determined from the information given.
(d) 4
Correct answer is (c)
Your score on this question is: 20.00
Feedback:
See section 1.4.1 of the course notes.
-------------------------------------------------------------------------------4.
When executing a function callee(), which of the following are true regarding t
he value of the frame pointer?
It marks the top of the stack frame of the function that invoked callee().
It marks the bottom of the stack frame of callee()
It is the top of the stack.

(a) II only
(b) III only
(c) I and II only
(d) I only
Correct answer is (c)
Your score on this question is: 0.00
Feedback:
See section 1.4.2 of the course notes.

-------------------------------------------------------------------------------5.
Activation records are organized in stacks because
(a) stacks are simple enough for the hardware to manage.
(b) stacks allow activation records to be pushed and popped in any order.
(c) functions need to access all the variables of the functions that call them.
(d) they are seldom needed during program execution.
Correct answer is (a)
Your score on this question is: 20.00
Feedback:
See section 1.4.2 of the course notes.
-------------------------------------------------------------------------------Go to top of assessment.
Total score: 80.00
? Copyright 2002 iCarnegie, Inc. All rights reserved.
View Assessment Result

Family Name: Han


Given Name: Lian
Login: nwpu043814
E-mail: october3rd@sina.com
Status: Active
Assessment Name: Multiple-Choice Quiz 5
Instance: 1
Section: NWPU-SSD6-2
During: Fall 2007
Section Status: Enrolled
For course: System-Level Programming
(SSD6)
Corresponding to: SSD6
At: Software College of Northwestern Polytechnical University
--------------------------------------------------------------------------------

Your performance was as follows:


You took 8 minutes on this assessment from Sat May 21 11:09:00 UTC+0800 2007 to
Sat May 21 11:16:14 UTC+0800 2007.

Total score: 40.00

1.
How many return addresses does a C function have as a program executes?
(a) as many as the number of times it is invoked
(b) one
(c) two, one for each branch
(d) as many as the number of return statements within the function
Correct answer is (a)
Your score on this question is: 20.00
Feedback:
See section 1.5.2 of the course notes.

-------------------------------------------------------------------------------2.
Consider the following pseudo-instructions.
0x40B7D8 i = i - 1
0x40B7E0 branch-if-not-zero 0x40B7D8
Which of the following code fragments do the instructions encode?
if (i != 0) i = i -1;
while (--i);
do { i = i - 1; } while (i);

(a) II only
(b) II and III only
(c) I only
(d) III only
Correct answer is (b)
Your score on this question is: 0.00
Feedback:
See section 1.5.2 of the course notes.
-------------------------------------------------------------------------------3.
A CPU register is a word of CPU memory that
(a) houses a critical variable for the duration of the execution of a program

(b) is explicitly loaded and unloaded from normal memory by compiler-generated


instructions
(c) is automatically loaded when a CPU instruction refers to a word of normal m
emory
(d) records the results of periodic CPU diagnostics
Correct answer is (b)
Your score on this question is: 0.00
Feedback:
See section 1.5.3 of the course notes.
-------------------------------------------------------------------------------4.
Which of the following computations may be performed by exactly one CPU instruc
tion?
a = 5;
a = b + c * 5;
for (i = 0; i < 10; i += a[i++]);

(a) I, II, and III


(b) I and II only
(c) II only
(d) I only
Correct answer is (d)
Your score on this question is: 20.00
Feedback:
See section 1.5.1 of the course notes.
-------------------------------------------------------------------------------5.
Programs compiled for an Intel Pentium processor do not execute properly on a S
PARC processor from Sun Microsystems because
(a) copyrights regarding code cannot be violated
(b) the assembly mnemonics for the same "opcode" are different in the two proce
ssors
(c) the operation codes understood by the two processors are different
(d) the memory of a SPARC CPU is numbered from top to bottom
Correct answer is (c)
Your score on this question is: 0.00
Feedback:
See section 1.5.1 of the course notes.
(b) The assembly mnemonics can be different and yet assemble into the same op
codes

-------------------------------------------------------------------------------Go to top of assessment.


Total score: 40.00
? Copyright 2002 iCarnegie, Inc. All rights reserved.
View Assessment Result
View Assessment Result: Multiple-Choice Quiz 1

Your performance was as follows:


1.
Consider the following fragment of C++ source code.
String msg; unsigned int x; int y;
cin >> msg >> x >> y;
cout << x + y;
Which of the following is (are) true regarding execution of the segment?
The input statement will always take the same amount of time to execute.
The output statement will always be executed immediately after the input stateme
nt.
If x and y are both positive, an integer greater than both will be printed.

(a) II only
(b) II and III only
(c) none
(d) I and II only
Correct answer is (c)
Your score on this question is: 7.14
Feedback:
See section 1.1.1 of the course notes.
-------------------------------------------------------------------------------2.
Compared to a sequence of machine code instructions, a fragment of C code
(a) does not engage any transistors during its execution
(b) is the native way to program most computers
(c) describes the actions of the computer, not just of the CPU
(d) may describe the same algorithm
Correct answer is (d)
Your score on this question is: 7.14

Feedback:
See section 1.1.2 of the course notes.
-------------------------------------------------------------------------------3.
Within Visual C++, which of the following will reveal the value of a variable w
hen the program is stopped at a breakpoint?
Placing the mouse pointer over the variable name in the source file window.
Inserting a printf() in the program.
Typing the variable name on the "Watch" window.

(a) III only


(b) II and III only
(c) I, II, and III
(d) I and III only
Correct answer is (d)
Your score on this question is: 7.14
Feedback:
See section 1.2.3 of the course notes.
-------------------------------------------------------------------------------4.
When using a debugger to find the cause of a program's incorrect behavior,
(a) it is often necessary to start the program multiple times under the debugg
er
(b) it is fastest to start by stopping the debugger long before the behavior ap
pears
(c) the faulty code fragment must first be identified
(d) the program is usually executed to the point at which the behavior occurs a
nd then executed backwards to find the cause
Correct answer is (a)
Your score on this question is: 7.14
Feedback:
See section 1.2.4 of the course notes.
-------------------------------------------------------------------------------5.
What is printed as a result of execution of the following program?
#include <stdio.h>
void callee(int * count) {
(*count)++;
}
int main (int argc, char *argv[]) {

int count = 4;
callee(&count);
printf("%d", count);
return 0;
}

(a) It cannot be determined from the information given.


(b) 8
(c) 5
(d) 4
Correct answer is (c)
Your score on this question is: 7.14
Feedback:
See section 1.4.1 of the course notes.
-------------------------------------------------------------------------------6.
What does the following program print?
int callee(int * count) {
count++;
return *count;
}
int main (int argc, char *argv[]) {
int count = 4;
int retval;
retval = callee(&count);
printf("%d", retval);
return 0;
}

(a) cannot be determined from the information given.


(b) 8
(c) 5
(d) 4
Correct answer is (a)
Your score on this question is: 7.14
Feedback:
See section 1.4.1 of the course notes.
-------------------------------------------------------------------------------7.
What does the following program print?
void callee(int * count) {
(*count)++;
}

int main (int argc, char *argv[]) {


int count = 4;
callee(count);
printf("%d", count);
return 0;
}

(a) 5
(b) 8
(c) 4
(d) nothing: it will not compile successfully
Correct answer is (d)
Your score on this question is: 0.00
Feedback:
See section 1.4.1 of the course notes.
-------------------------------------------------------------------------------8.
When executing a function callee(), which of the following are true regarding t
he value of the frame pointer?
It marks the top of the stack frame of the function that invoked callee().
It marks the bottom of the stack frame of callee()
It is the top of the stack.

(a) I only
(b) I and II only
(c) III only
(d) II only
Correct answer is (b)
Your score on this question is: 7.14
Feedback:
See section 1.4.2 of the course notes.
-------------------------------------------------------------------------------9.
Consider the following segment of C source code.
int a = 8;
int b = *&a;
What is the value of variable b at the end of execution of the segment?
(a) a
(b) (int) &b
(c) &a

(d) (int) &a


Correct answer is (a)
Your score on this question is: 7.14
Feedback:
See section 1.3.2 of the course notes.
-------------------------------------------------------------------------------10.
Consider the following code.
char a[100];
a[99] = *((char *) (((int) &a[0]) + 4))
If integers are 32 bits wide, which of the following values is equal to a[99]?
(a) a[0] + 4
(b) a[3]
(c) a[4]
(d) the integer stored in the bytes a[4], a[5], a[6] and a[7]
Correct answer is (c)
Your score on this question is: 7.14
Feedback:
See section 1.3.5 of the course notes.
-------------------------------------------------------------------------------11.
The program counter contains
(a) the number of CPU instructions a program has executed so far
(b) the amount of memory a program is currently using
(c) the number of times a program has been executed
(d) the address of the CPU instruction that is about to be executed
Correct answer is (d)
Your score on this question is: 7.14
Feedback:
See section 1.5.2 of the course notes.
-------------------------------------------------------------------------------12.
Which of the following is a good reason (are good reasons) to equip the CPU wit
h small amounts of fast memory?
To make the design of the compiler simpler
To make some CPU instructions smaller
To make some CPU instructions faster

(a) III only


(b) I, II, and III
(c) II and III only
(d) II only
Correct answer is (c)
Your score on this question is: 7.14
Feedback:
See section 1.5.3 of the course notes.
-------------------------------------------------------------------------------13.
We want the variable factorialfunc to hold the address of the first instruction
of the following function:
int factorial(int n) {
if (n == 1) return n;
return n * factorial(n -1);
}
How would we declare the variable?
(a) we can't: C cannot extract the addresses of instructions.
(b) int (*factorialfunc)(int);
(c) int (int) * factorialfunc
(d) factorial() * factorialfunc;
Correct answer is (b)
Your score on this question is: 7.14
Feedback:
See section 1.5.2 of the course notes.
-------------------------------------------------------------------------------14.
Consider the following pseudo-instructions.
0x40B7D8 i = i - 1
0x40B7E0 branch-if-not-zero 0x40B7D8
Which of the following code fragments do the instructions encode?
if (i != 0) i = i -1;
while (--i);
do { i = i - 1; } while (i);

(a) I only
(b) II and III only
(c) II only
(d) III only

Correct answer is (b)


Your score on this question is: 7.14
Feedback:
See section 1.5.2 of the course notes.
-------------------------------------------------------------------------------Go to top of assessment.
Total score: 92.86
? Copyright 2005 iCarnegie, Inc. All rights reserved.

Family Name: Han


Given Name: Lian
Login: nwpu043814
E-mail: october3rd@sina.com
Status: Active
Assessment Name: Multiple-Choice Quiz 5
Instance: 2
Section: NWPU-SSD6-2
During: Fall 2007
Section Status: Enrolled
For course: System-Level Programming
(SSD6)
Corresponding to: SSD6
At: Software College of Northwestern Polytechnical University
--------------------------------------------------------------------------------

Your performance was as follows:


You took 2 minutes on this assessment from Sat May 21 11:17:08 UTC+0800 2007 to
Sat May 21 11:18:59 UTC+0800 2007.
Total score: 60.00

1.
The program counter contains
(a) the amount of memory a program is currently using

(b) the number of times a program has been executed


(c) the address of the CPU instruction that is about to be executed
(d) the number of CPU instructions a program has executed so far
Correct answer is (c)
Your score on this question is: 20.00
Feedback:
See section 1.5.2 of the course notes.

-------------------------------------------------------------------------------2.
A branch instruction
(a) increases the program counter by a fixed amount
(b) sets the program counter to one of two possible values
(c) sets the program counter to one of many possible values
(d) unconditionally sets the program counter to its operand
Correct answer is (b)
Your score on this question is: 0.00
Feedback:
See section 1.5.2 of the course notes.
-------------------------------------------------------------------------------3.
Which of the following is a good reason (are good reasons) to equip the CPU wit
h small amounts of fast memory?
To make the design of the compiler simpler
To make some CPU instructions smaller
To make some CPU instructions faster

(a) II only
(b) III only
(c) I, II, and III
(d) II and III only
Correct answer is (d)
Your score on this question is: 0.00
Feedback:
See section 1.5.3 of the course notes.
-------------------------------------------------------------------------------4.

Which of the following computations may be performed by exactly one CPU instruc
tion?
a = 5;
a = b + c * 5;
for (i = 0; i < 10; i += a[i++]);

(a) II only
(b) I only
(c) I and II only
(d) I, II, and III
Correct answer is (b)
Your score on this question is: 20.00
Feedback:
See section 1.5.1 of the course notes.
-------------------------------------------------------------------------------5.
Programs compiled for an Intel Pentium processor do not execute properly on a S
PARC processor from Sun Microsystems because
(a) copyrights regarding code cannot be violated
(b) the operation codes understood by the two processors are different
(c) the assembly mnemonics for the same "opcode" are different in the two proce
ssors
(d) the memory of a SPARC CPU is numbered from top to bottom
Correct answer is (b)
Your score on this question is: 20.00
Feedback:
See section 1.5.1 of the course notes.
-------------------------------------------------------------------------------Go to top of assessment.
Total score: 60.00
? Copyright 2002 iCarnegie, Inc. All rights reserved.
View Assessment Result

Family Name: Han


Given Name: Lian
Login: nwpu043814
E-mail: october3rd@sina.com
Status: Active

Assessment Name: Multiple-Choice Quiz 5


Instance: 3
Section: NWPU-SSD6-2
During: Fall 2007
Section Status: Enrolled
For course: System-Level Programming
(SSD6)
Corresponding to: SSD6
At: Software College of Northwestern Polytechnical University
--------------------------------------------------------------------------------

Your performance was as follows:


You took 3 minutes on this assessment from Sat May 21 11:20:17 UTC+0800 2007 to
Sat May 21 11:22:38 UTC+0800 2007.
Total score: 80.00

1.
We want the variable factorialfunc to hold the address of the first instruction
of the following function:
int factorial(int n) {
if (n == 1) return n;
return n * factorial(n -1);
}
How would we declare the variable?
(a) factorial() * factorialfunc;
(b) int (int) * factorialfunc
(c) we can't: C cannot extract the addresses of instructions.
(d) int (*factorialfunc)(int);
Correct answer is (d)
Your score on this question is: 20.00
Feedback:
See section 1.5.2 of the course notes.

-------------------------------------------------------------------------------2.
A branch instruction

(a) sets the program counter to one of two possible values


(b) increases the program counter by a fixed amount
(c) unconditionally sets the program counter to its operand
(d) sets the program counter to one of many possible values
Correct answer is (a)
Your score on this question is: 20.00
Feedback:
See section 1.5.2 of the course notes.
-------------------------------------------------------------------------------3.
Which of the following
chine code generated by
The resulting code will
The resulting code will
The resulting code will

are true of the effect that optimizations have on the ma


compilers?
be faster and/or smaller.
be clearer.
be harder to debug.

(a) I and III only


(b) I and II only
(c) I, II, and III
(d) I only
Correct answer is (a)
Your score on this question is: 0.00
Feedback:
See section 1.5.3 of the course notes.
-------------------------------------------------------------------------------4.
Programs compiled for an Intel Pentium processor do not execute properly on a S
PARC processor from Sun Microsystems because
(a) the memory of a SPARC CPU is numbered from top to bottom
(b) copyrights regarding code cannot be violated
(c) the assembly mnemonics for the same "opcode" are different in the two proce
ssors
(d) the operation codes understood by the two processors are different
Correct answer is (d)
Your score on this question is: 20.00
Feedback:
See section 1.5.1 of the course notes.

-------------------------------------------------------------------------------5.
Suppose that, using a tool such as the memory window of Visual C++, we found th
at a certain set of contiguous memory locations contained the integer 0xC605CD62
3A8365000000. What could these memory locations hold?
the integer 0xC605CD623A8365000000
a string
a CPU instruction

(a) I, II, and III


(b) III only
(c) I and II only
(d) I only
Correct answer is (a)
Your score on this question is: 20.00
Feedback:
See section 1.5.1 of the course notes.
-------------------------------------------------------------------------------Go to top of assessment.
Total score: 80.00
? Copyright 2002 iCarnegie, Inc. All rights reserved.
View Assessment Result

Family Name: Han


Given Name: Lian
Login: nwpu043814
E-mail: october3rd@sina.com
Status: Active
Assessment Name: Multiple-Choice Quiz 6
Instance: 1
Section: NWPU-SSD6-2
During: Fall 2007
Section Status: Enrolled
For course: System-Level Programming
(SSD6)
Corresponding to: SSD6
At: Software College of Northwestern Polytechnical University
--------------------------------------------------------------------------------

Your performance was as follows:


You took 8 minutes on this assessment from Sat Apr 30 11:01:58 UTC+0800 2007 to
Sat Apr 30 11:09:10 UTC+0800 2007.
Total score: 75.00

1.
Which of the following could be represented by one bit of information?
(a) the position of a light switch
(b) the color of a single pixel on a true-color computer display
(c) the current channel of a television receiver
(d) an ASCII character
Correct answer is (a)
Your score on this question is: 25.00
Feedback:
See section 2.1.1 of the course notes.

-------------------------------------------------------------------------------2.
Which of the following explains why it is convenient to use hexadecimal notatio
n when programming?
(a) Hexadecimal can represent larger numbers than decimal.
(b) Hexadecimal digits line up with bit and byte boundaries.
(c) Memory is accessed in 4-bit chunks.
(d) Not all computer numbers can be written in decimal form.
Correct answer is (b)
Your score on this question is: 0.00
Feedback:
See section 2.1.2 of the course notes.
-------------------------------------------------------------------------------3.
What is the value of the following C expression?
0x1234 ^ 0x5432
(a) 0x5636

(b) 0x4606
(c) 0x1030
(d) 0x5434
Correct answer is (b)
Your score on this question is: 25.00
Feedback:
See section 2.1.3 of the course notes.
-------------------------------------------------------------------------------4.
What is the value of the following C expression?
0x1234 << 3
(a) 0x1234000
(b) 0x48CE
(c) 0x9340
(d) 0x91A0
Correct answer is (d)
Your score on this question is: 25.00
Feedback:
See section 2.1.3 of the course notes.
-------------------------------------------------------------------------------Go to top of assessment.
Total score: 75.00
? Copyright 2002 iCarnegie, Inc. All rights reserved.
View Assessment Result

Family Name: Han


Given Name: Lian
Login: nwpu043814
E-mail: october3rd@sina.com
Status: Active
Assessment Name: Multiple-Choice Quiz 6
Instance: 2
Section: NWPU-SSD6-2
During: Fall 2007
Section Status: Enrolled
For course: System-Level Programming
(SSD6)

Corresponding to: SSD6


At: Software College of Northwestern Polytechnical University
--------------------------------------------------------------------------------

Your performance was as follows:


You took 4 minutes on this assessment from Sat Apr 30 11:10:31 UTC+0800 2007 to
Sat Apr 30 11:13:36 UTC+0800 2007.
Total score: 100.00

1.
Which of the following could be represented by one bit of information?
(a) the current channel of a television receiver
(b) the position of a light switch
(c) an ASCII character
(d) the color of a single pixel on a true-color computer display
Correct answer is (b)
Your score on this question is: 25.00
Feedback:
See section 2.1.1 of the course notes.

-------------------------------------------------------------------------------2.
Which of the following explains why it is convenient to use hexadecimal notatio
n when programming?
(a) Memory is accessed in 4-bit chunks.
(b) Not all computer numbers can be written in decimal form.
(c) Hexadecimal digits line up with bit and byte boundaries.
(d) Hexadecimal can represent larger numbers than decimal.
Correct answer is (c)
Your score on this question is: 25.00
Feedback:
See section 2.1.2 of the course notes.
--------------------------------------------------------------------------------

3.
What is the value of the following C expression?
0x1234 << 3
(a) 0x48CE
(b) 0x1234000
(c) 0x9340
(d) 0x91A0
Correct answer is (d)
Your score on this question is: 25.00
Feedback:
See section 2.1.3 of the course notes.
-------------------------------------------------------------------------------4.
What is the value of the following C expression?
0x1234 >> 5
(a) 0x0000
(b) 0x00A3
(c) 0x0092
(d) 0x0091
Correct answer is (d)
Your score on this question is: 25.00
Feedback:
See section 2.1.3 of the course notes.
-------------------------------------------------------------------------------Go to top of assessment.
Total score: 100.00
? Copyright 2002 iCarnegie, Inc. All rights reserved.
View Assessment Result

Family Name: Han


Given Name: Lian
Login: nwpu043814
E-mail: october3rd@sina.com
Status: Active
Assessment Name: Multiple-Choice Quiz 7
Instance: 1

Section: NWPU-SSD6-2
During: Fall 2007
Section Status: Enrolled
For course: System-Level Programming
(SSD6)
Corresponding to: SSD6
At: Software College of Northwestern Polytechnical University
--------------------------------------------------------------------------------

Your performance was as follows:


You took 5 minutes on this assessment from Thu May 12 15:27:57 UTC+0800 2007 to
Thu May 12 15:32:43 UTC+0800 2007.
Total score: 75.00

1.
In a computer with 4-byte words, which of the following C expressions tests whe
ther ptr contains the address of a word?
(ptr & 3) == 0
(ptr | 3) == 0
(ptr % 4) == 0

(a) I only
(b) I and III only
(c) III only
(d) II only
Correct answer is (b)
Your score on this question is: 0.00
Feedback:
See section 2.2.1 of the course notes.

-------------------------------------------------------------------------------2.
How is 46 (decimal) represented in an 8-bit 2's complement binary format?
(a) 01000110
(b) 00011110
(c) 00101100

(d) 00101110
Correct answer is (d)
Your score on this question is: 25.00
Feedback:
See section 2.2.1 of the course notes.
-------------------------------------------------------------------------------3.
In modern computers, each address represents one _____ of memory.
(a) word
(b) bit
(c) page
(d) byte
Correct answer is (d)
Your score on this question is: 25.00
Feedback:
See section 2.2.1 of the course notes.
-------------------------------------------------------------------------------4.
What happens in a C program when an addition would cause integer overflow?
(a) An incorrect result is produced and execution continues.
(b) An exception-handler is called with the two operands as parameters.
(c) Execution is terminated.
(d) The correct value is coerced to a floating point number.
Correct answer is (a)
Your score on this question is: 25.00
Feedback:
See section 2.2.2 of the course notes.
-------------------------------------------------------------------------------Go to top of assessment.
Total score: 75.00
? Copyright 2002 iCarnegie, Inc. All rights reserved.
View Assessment Result

Family Name: Han


Given Name: Lian
Login: nwpu043814
E-mail: october3rd@sina.com
Status: Active
Assessment Name: Multiple-Choice Quiz 8
Instance: 1
Section: NWPU-SSD6-2
During: Fall 2007
Section Status: Enrolled
For course: System-Level Programming
(SSD6)
Corresponding to: SSD6
At: Software College of Northwestern Polytechnical University
--------------------------------------------------------------------------------

Your performance was as follows:


You took 8 minutes on this assessment from Thu May 12 16:32:01 UTC+0800 2007 to
Thu May 12 16:39:23 UTC+0800 2007.
Total score: 50.00

1.
What is the purpose of the exponent in floating point numbers?
(a) the mantissa is raised to the power of the exponent
(b) to indicate where the decimal or binary point should be
(c) to specify the base as binary, octal, or hexadecimal
(d) to specify the superscript
Correct answer is (b)
Your score on this question is: 0.00
Feedback:
See section 2.3.1 of the course notes.

-------------------------------------------------------------------------------2.
Which of the following statements about floating-point numbers in C is true?
Floating-point numbers are often only approximations of real numbers.

A 32-bit float only approximates decimal fractions, but a 64-bit double represen
ts them exactly.
Floating-point numbers can represent any rational real number but not irrational
s.

(a) I and III only


(b) I and II only
(c) II only
(d) I only
Correct answer is (d)
Your score on this question is: 25.00
Feedback:
See section 2.3.2 of the course notes.
-------------------------------------------------------------------------------3.
Which of the following numerical operations is most likely to lead to loss of p
recision?
(a) Floating-point multiplication
(b) Floating-point addition
(c) Integer addition
(d) Integer multiplication
Correct answer is (b)
Your score on this question is: 25.00
Feedback:
See section 2.3.2 of the course notes.
-------------------------------------------------------------------------------4.
In C, using default floating point settings, what happens when a floating-point
computation results in an overflow?
(a) An erroneous value is computed and execution continues.
(b) A special value "infinity" is computed, testable with _finite().
(c) An exception is raised unless disabled by calling _controlfp().
(d) Program execution is halted.
Correct answer is (b)
Your score on this question is: 0.00
Feedback:
See section 2.3.3 of the course notes.

-------------------------------------------------------------------------------Go to top of assessment.


Total score: 50.00
? Copyright 2002 iCarnegie, Inc. All rights reserved.
View Assessment Result

Family Name: Han


Given Name: Lian
Login: nwpu043814
E-mail: october3rd@sina.com
Status: Active
Assessment Name: Multiple-Choice Quiz 8
Instance: 2
Section: NWPU-SSD6-2
During: Fall 2007
Section Status: Enrolled
For course: System-Level Programming
(SSD6)
Corresponding to: SSD6
At: Software College of Northwestern Polytechnical University
--------------------------------------------------------------------------------

Your performance was as follows:


You took 3 minutes on this assessment from Thu May 12 16:41:24 UTC+0800 2007 to
Thu May 12 16:44:20 UTC+0800 2007.
Total score: 75.00

1.
Why is the mantissa of a floating point number shifted left as far as possible?

(a) to align bit positions, simplifying addition


(b) to avoid overflow
(c) to avoid underflow
(d) to retain as much precision as possible
Correct answer is (d)

Your score on this question is: 25.00


Feedback:
See section 2.3.1 of the course notes.

-------------------------------------------------------------------------------2.
Which of the following numerical operations is most likely to lead to loss of p
recision?
(a) Floating-point addition
(b) Floating-point multiplication
(c) Integer addition
(d) Integer multiplication
Correct answer is (a)
Your score on this question is: 25.00
Feedback:
See section 2.3.2 of the course notes.
-------------------------------------------------------------------------------3.
Which of the following statements about floating-point numbers in C is true?
Floating-point numbers are often only approximations of real numbers.
A 32-bit float only approximates decimal fractions, but a 64-bit double represen
ts them exactly.
Floating-point numbers can represent any rational real number but not irrational
s.

(a) II only
(b) I only
(c) I and III only
(d) I and II only
Correct answer is (b)
Your score on this question is: 0.00
Feedback:
See section 2.3.2 of the course notes.
-------------------------------------------------------------------------------4.
In C, using default floating point settings, what happens when a floating-point
computation results in an overflow?

(a) An erroneous value is computed and execution continues.


(b) An exception is raised unless disabled by calling _controlfp().
(c) Program execution is halted.
(d) A special value "infinity" is computed, testable with _finite().
Correct answer is (d)
Your score on this question is: 25.00
Feedback:
See section 2.3.3 of the course notes.
-------------------------------------------------------------------------------Go to top of assessment.
Total score: 75.00
? Copyright 2002 iCarnegie, Inc. All rights reserved.
View Assessment Result

Family Name: Han


Given Name: Lian
Login: nwpu043814
E-mail: october3rd@sina.com
Status: Active
Assessment Name: Multiple-Choice Quiz 9
Instance: 1
Section: NWPU-SSD6-2
During: Fall 2007
Section Status: Enrolled
For course: System-Level Programming
(SSD6)
Corresponding to: SSD6
At: Software College of Northwestern Polytechnical University
--------------------------------------------------------------------------------

Your performance was as follows:


You took 12 minutes on this assessment from Thu May 12 16:54:04 UTC+0800 2007 t
o Thu May 12 17:05:50 UTC+0800 2007.
Total score: 80.00

1.
Which of
Alignment
Alignment
Alignment

the following statements about alignment within C struct's is true?


may cause the allocation of unused space.
is required by all modern processors.
can help processors access data more efficiently.

(a) I, II, and III


(b) I and III only
(c) II and III only
(d) I only
Correct answer is (b)
Your score on this question is: 20.00
Feedback:
See section 2.4.3 of the course notes.

-------------------------------------------------------------------------------2.
Assume that array a is at location 1000 (decimal). Execution of the following p
rogram results in what being printed?
int a[12];
main() {
int i;
for (i = 0; i < 12; i++) a[i] = i;
printf("%d\n", *(a + 5));
}

(a) 1005
(b) 1020
(c) 20
(d) 5
Correct answer is (d)
Your score on this question is: 20.00
Feedback:
See section 2.4.1 of the course notes.
-------------------------------------------------------------------------------3.
Given the following declaration and initialization of s, what is the value of t
he expression s[6]?
char s[] = "string";

(a) 'g'
(b) '\n'
(c) '\0'
(d) an unpredictable value
Correct answer is (c)
Your score on this question is: 20.00
Feedback:
See section 2.4.1 of the course notes.
-------------------------------------------------------------------------------4.
How many bytes are allocated by the following C declaration and initialization?
char s[] = "quiz";
(a) 4
(b) 20
(c) 16
(d) 5
Correct answer is (d)
Your score on this question is: 20.00
Feedback:
See section 2.4.1 of the course notes.
-------------------------------------------------------------------------------5.
Given the address of a C struct at runtime, how is the address of a member elem
ent in the struct determined?
(a) The struct consists of an array of pointers to the elements of the struct.
(b) A constant offset associated with the member is added to the address.
(c) A linear search is made from the base address of the struct.
(d) The element name is looked up in a symbol table.
Correct answer is (b)
Your score on this question is: 0.00
Feedback:
See section 2.4.2 of the course notes.
-------------------------------------------------------------------------------Go to top of assessment.
Total score: 80.00

? Copyright 2002 iCarnegie, Inc. All rights reserved.


View Assessment Result

Family Name: Han


Given Name: Lian
Login: nwpu043814
E-mail: october3rd@sina.com
Status: Active
Assessment Name: Multiple-Choice Quiz 10
Instance: 1
Section: NWPU-SSD6-2
During: Fall 2007
Section Status: Enrolled
For course: System-Level Programming
(SSD6)
Corresponding to: SSD6
At: Software College of Northwestern Polytechnical University
--------------------------------------------------------------------------------

Your performance was as follows:


You took 8 minutes on this assessment from Sat Jun 4 11:03:21 UTC+0800 2007 to
Sat Jun 4 11:10:59 UTC+0800 2007.
Total score: 100.00

1.
What properties of a variable are specified by the static keyword in C?
The variable will be statically allocated.
The variable name will be visible only to functions defined within the same file
.
The variable's value does not change very often. The compiler uses this fact to
focus optimizations on other variables.

(a) I and II only.


(b) III only
(c) I only
(d) I and III only.
Correct answer is (a)
Your score on this question is: 20.00

Feedback:
See section 3.1.1 of the course notes.

-------------------------------------------------------------------------------2.
Which of the following features apply to standard heap allocation in C?
The size of heap objects must be known at compile time.
Heap memory must be explicitly allocated.
Heap memory is deallocated when a function returns.

(a) I only.
(b) I and III.
(c) II only.
(d) I and II only.
Correct answer is (c)
Your score on this question is: 20.00
Feedback:
See section 3.1.2 of the course notes.
-------------------------------------------------------------------------------3.
In C, local variables allocated inside functions are allocated
(a) on the stack
(b) in static storage
(c) in a fifo
(d) in the heap
Correct answer is (a)
Your score on this question is: 20.00
Feedback:
See section 3.1.2 of the course notes.
-------------------------------------------------------------------------------4.
Suppose a compiler uses static storage to store all variables, function paramet
ers, saved registers, and return addresses. Which of the following language feat
ures can this compiler support?
Local variables.
Function calls.
Recursion.

(a) I only
(b) I, II, and III
(c) II only
(d) I and II only
Correct answer is (d)
Your score on this question is: 20.00
Feedback:
See section 3.1.2 of the course notes.
-------------------------------------------------------------------------------5.
In C, how are local variables found at run-time?
(a) The programmer keeps pointers to their location on the heap.
(b) The variables are located at fixed offsets from a frame pointer.
(c) The variables are always stored at the same address, determined by the link
er.
(d) The variables are stored at a fixed offset from the program counter.
Correct answer is (b)
Your score on this question is: 20.00
Feedback:
See section 3.1.2 of the course notes.
-------------------------------------------------------------------------------Go to top of assessment.
Total score: 100.00
? Copyright 2002 iCarnegie, Inc. All rights reserved.
View Assessment Result
View Assessment Result

Family Name: Han


Given Name: Lian
Login: nwpu043814
E-mail: october3rd@sina.com
Status: Active
Assessment Name: Multiple-Choice Quiz 11
Instance: 1
Section: NWPU-SSD6-2

During: Fall 2007


Section Status: Enrolled
For course: System-Level Programming
(SSD6)
Corresponding to: SSD6
At: Software College of Northwestern Polytechnical University
--------------------------------------------------------------------------------

Your performance was as follows:


You took 9 minutes on this assessment from Mon Jun 6 13:04:48 UTC+0800 2007 to
Mon Jun 6 13:13:44 UTC+0800 2007.
Total score: 90.00
View Assessment Result: Multiple-Choice Quiz 3

Your performance was as follows:


1.
In C, how are local variables found at run-time?
(a) The programmer keeps pointers to their location on the heap.
(b) The variables are always stored at the same address, determined by the link
er.
(c) The variables are stored at a fixed offset from the program counter.
(d) The variables are located at fixed offsets from a frame pointer.
Correct answer is (d)
Your score on this question is: 16.67
Feedback:
See section 3.1.2 of the course notes.
-------------------------------------------------------------------------------2.
Which of the following features apply to standard heap allocation in C?
The size of heap objects must be known at compile time.
Heap memory must be explicitly allocated.
Heap memory is deallocated when a function returns.

(a) I and II only.


(b) I only.

(c) I and III.


(d) II only.
Correct answer is (d)
Your score on this question is: 16.67
Feedback:
See section 3.1.2 of the course notes.
-------------------------------------------------------------------------------3.
Why is it wrong to return the address of a local variable?
(a) The variable address is invalid after the return.
(b) It allows illegal access to the variable from arbitrary functions.
(c) It is faster to return the value of the variable.
(d) The local variable may be in a machine register.
Correct answer is (a)
Your score on this question is: 16.67
Feedback:
See section 3.3.3 of the course notes.
-------------------------------------------------------------------------------4.
In this sequence of C statements
long a[10];
ptr = a + 5;
*ptr++ = x;
the last line could be rewritten as
(a) a[5] = x; ptr = ptr + 1;
(b) ptr = x; *ptr++;
(c) ptr = ptr + 1; *ptr = x;
(d) a[6] = x;
Correct answer is (a)
Your score on this question is: 0.00
Feedback:
See section 3.3.1 of the course notes.
-------------------------------------------------------------------------------5.
In C, calloc() differs from malloc() in that calloc()

(a) allocates additional memory from the stack.


(b) detects memory allocation errors.
(c) is faster.
(d) sets the contents of the block to zero before returning.
Correct answer is (d)
Your score on this question is: 16.67
Feedback:
See section 3.3.2 of the course notes.
-------------------------------------------------------------------------------6.
The unary & operator returns
(a) the address of a data object.
(b) the contents of memory at a given address.
(c) the operand unaltered.
(d) the logical "and" of two integer operands.
Correct answer is (a)
Your score on this question is: 16.67
Feedback:
See section 3.3.1 of the course notes.
-------------------------------------------------------------------------------Go to top of assessment.
Total score: 83.33
? Copyright 2005 iCarnegie, Inc. All rights reserved.

1.
In C, calloc() differs from malloc() in that calloc()
(a) detects memory allocation errors.
(b) is faster.
(c) sets the contents of the block to zero before returning.
(d) allocates additional memory from the stack.
Correct answer is (c)
Your score on this question is: 10.00
Feedback:
See section 3.3.2 of the course notes.

-------------------------------------------------------------------------------2.
The unary & operator returns
(a) the operand unaltered.
(b) the contents of memory at a given address.
(c) the logical "and" of two integer operands.
(d) the address of a data object.
Correct answer is (d)
Your score on this question is: 10.00
Feedback:
See section 3.3.1 of the course notes.
-------------------------------------------------------------------------------3.
The C expression a->b is equivalent to
(a) (&a) + b
(b) *(a + b)
(c) (*a).b
(d) (&a).b
Correct answer is (c)
Your score on this question is: 10.00
Feedback:
See section 3.3.1 of the course notes.
-------------------------------------------------------------------------------4.
Why is it wrong to return the address of a local variable?
(a) The local variable may be in a machine register.
(b) It allows illegal access to the variable from arbitrary functions.
(c) It is faster to return the value of the variable.
(d) The variable address is invalid after the return.
Correct answer is (d)
Your score on this question is: 10.00
Feedback:
See section 3.3.3 of the course notes.
--------------------------------------------------------------------------------

5.
In C, to allocate an array of 100 longs on the heap you should write
(a) long a[100] = (long *) malloc(sizeof(a));
(b) long *a = (long *) malloc(100);
(c) long a[] = (long *) malloc(100);
(d) long *a = (long *) malloc(100 * sizeof(long));
Correct answer is (d)
Your score on this question is: 10.00
Feedback:
See section 3.3.3 of the course notes.
-------------------------------------------------------------------------------6.
Consider the following fragment of C code.
int *p = (int *) calloc(100);
int *q = p;
free(p);
Immediately after executing it, which of the following are true about p and q?
p and q are identical pointers to freed storage.
p points to freed storage, and q points to an allocated block of size 100.
p should not be free()d again, but invoking free(q) is all right.

(a) I only
(b) II and III only
(c) II only
(d) III only
Correct answer is (a)
Your score on this question is: 10.00
Feedback:
See section 3.3.4 of the course notes.
-------------------------------------------------------------------------------7.
A memory leak is caused by a
(a) bug in which too much memory is allocated, causing internal fragmentation
(b) function that allocates a large amount of memory from the heap
(c) failure to free allocated memory
(d) bug in the memory allocator that fails to free memory
Correct answer is (c)
Your score on this question is: 10.00

Feedback:
See section 3.3.5 of the course notes.
-------------------------------------------------------------------------------8.
In C, when a struct is freed,
(a) no pointers within the struct are freed automatically.
(b) a destructor function is called automatically to clean up.
(c) only those pointers within the struct that point into the heap are freed au
tomatically.
(d) any pointers within the struct are also freed automatically.
Correct answer is (a)
Your score on this question is: 10.00
Feedback:
See section 3.3.5 of the course notes.
-------------------------------------------------------------------------------9.
To resolve memory leaks in C, one common approach is
(a) to ensure that memory blocks are allocated only on word boundaries.
(b) to store the source code line whence each block is allocated.
(c) to add padding before and after allocated memory blocks and to fill that me
mory with a known value.
(d) to check whether the number of calls to malloc() is greater than the number
of calls to free().
Correct answer is (b)
Your score on this question is: 0.00
Feedback:
See section 3.3.6 of the course notes.
-------------------------------------------------------------------------------10.
Reference counts used in implementations of garbage collectors count
(a) the number of pointers pointing to a block.
(b) the number of times a block has been accessed.
(c) the number of times a datum has been referenced inside each block.
(d) the number of times a block has been allocated.
Correct answer is (a)
Your score on this question is: 10.00

Feedback:
See section 3.3.7 of the course notes.
-------------------------------------------------------------------------------Go to top of assessment.
Total score: 90.00
? Copyright 2002 iCarnegie, Inc. All rights reserved.
View Assessment Result

Family Name: Han


Given Name: Lian
Login: nwpu043814
E-mail: october3rd@sina.com
Status: Active
Assessment Name: Multiple-Choice Quiz 12
Instance: 1
Section: NWPU-SSD6-2
During: Fall 2007
Section Status: Enrolled
For course: System-Level Programming
(SSD6)
Corresponding to: SSD6
At: Software College of Northwestern Polytechnical University
--------------------------------------------------------------------------------

Your performance was as follows:


You took 33 minutes on this assessment from Thu Jun 9 16:38:22 UTC+0800 2007 to
Thu Jun 9 17:10:28 UTC+0800 2007.
Total score: 40.00

1.
"Wall time" measures
(a) the total duration of a program's execution.
(b) the user time plus the system time.
(c) the time a program spends waiting for input and output.

(d) idle time.


Correct answer is (a)
Your score on this question is: 20.00
Feedback:
See section 4.1.1 of the course notes.

-------------------------------------------------------------------------------2.
Which of the following approaches towards optimizing programs is most advisable
?
(a) Optimize the more complex functions first.
(b) "Optimize as you go": make sure every function is optimized before writing
the next one.
(c) Optimize after all functions are written and debugged.
(d) Optimize main() first.
Correct answer is (c)
Your score on this question is: 0.00
Feedback:
See section 4.1.1 of the course notes.
-------------------------------------------------------------------------------3.
"CPU time" measures
(a) the time spent executing system functions.
(b) the percentage utilization of the CPU by the system.
(c) wall time
(d) the time spent by a program executing program instructions.
Correct answer is (d)
Your score on this question is: 20.00
Feedback:
See section 4.1.1 of the course notes.
-------------------------------------------------------------------------------4.
Which of the following are useful for observing program performance?
Direct measurement with a stopwatch.
Statistical Sampling.
System Monitors

(a) I and III only


(b) I, II, and III
(c) II and III only
(d) I and II only
Correct answer is (b)
Your score on this question is: 0.00
Feedback:
See section 4.1.2 of the course notes.
-------------------------------------------------------------------------------5.
Which of the following are advantages of using statistical sampling to profile
programs?
Exact run times of all functions can be determined.
Code can be instrumented automatically.
The performance impact due to measurement can be minimal.

(a) I and II only


(b) II and III only
(c) I and III only
(d) I, II, and III
Correct answer is (b)
Your score on this question is: 0.00
Feedback:
See section 4.1.2 of the course notes.
-------------------------------------------------------------------------------Go to top of assessment.
Total score: 40.00
? Copyright 2002 iCarnegie, Inc. All rights reserved.
View Assessment Result

Family Name: Han


Given Name: Lian
Login: nwpu043814
E-mail: october3rd@sina.com
Status: Active
Assessment Name: Multiple-Choice Quiz 12
Instance: 2

Section: NWPU-SSD6-2
During: Fall 2007
Section Status: Enrolled
For course: System-Level Programming
(SSD6)
Corresponding to: SSD6
At: Software College of Northwestern Polytechnical University
--------------------------------------------------------------------------------

Your performance was as follows:


You took 3 minutes on this assessment from Thu Jun 9 17:11:14 UTC+0800 2007 to
Thu Jun 9 17:14:00 UTC+0800 2007.
Total score: 80.00

1.
"Wall time" measures
(a) the user time plus the system time.
(b) the total duration of a program's execution.
(c) idle time.
(d) the time a program spends waiting for input and output.
Correct answer is (b)
Your score on this question is: 20.00
Feedback:
See section 4.1.1 of the course notes.

-------------------------------------------------------------------------------2.
Which of the following approaches towards optimizing programs is most advisable
?
(a) Optimize after all functions are written and debugged.
(b) Optimize main() first.
(c) Optimize the more complex functions first.
(d) "Optimize as you go": make sure every function is optimized before writing
the next one.
Correct answer is (a)

Your score on this question is: 0.00


Feedback:
See section 4.1.1 of the course notes.
-------------------------------------------------------------------------------3.
"CPU time" measures
(a) the time spent executing system functions.
(b) wall time
(c) the percentage utilization of the CPU by the system.
(d) the time spent by a program executing program instructions.
Correct answer is (d)
Your score on this question is: 20.00
Feedback:
See section 4.1.1 of the course notes.
-------------------------------------------------------------------------------4.
Which of the following are useful for observing program performance?
Direct measurement with a stopwatch.
Statistical Sampling.
System Monitors

(a) I and II only


(b) I, II, and III
(c) I and III only
(d) II and III only
Correct answer is (b)
Your score on this question is: 20.00
Feedback:
See section 4.1.2 of the course notes.
-------------------------------------------------------------------------------5.
Which of the following are advantages of using statistical sampling to profile
programs?
Exact run times of all functions can be determined.
Code can be instrumented automatically.
The performance impact due to measurement can be minimal.

(a) I and II only


(b) I and III only
(c) II and III only
(d) I, II, and III
Correct answer is (c)
Your score on this question is: 20.00
Feedback:
See section 4.1.2 of the course notes.
-------------------------------------------------------------------------------Go to top of assessment.
Total score: 80.00
? Copyright 2002 iCarnegie, Inc. All rights reserved.
View Assessment Result

Family Name: Han


Given Name: Lian
Login: nwpu043814
E-mail: october3rd@sina.com
Status: Active
Assessment Name: Multiple-Choice Quiz 13
Instance: 1
Section: NWPU-SSD6-2
During: Fall 2007
Section Status: Enrolled
For course: System-Level Programming
(SSD6)
Corresponding to: SSD6
At: Software College of Northwestern Polytechnical University
--------------------------------------------------------------------------------

Your performance was as follows:


You took 7 minutes on this assessment from Tue Jun 28 01:28:41 UTC+0800 2007 to
Tue Jun 28 01:35:23 UTC+0800 2007.
Total score: 60.00

1.
Which of the following is likely to offer the best performance improvement for
programs that spend 50% of their time comparing strings?
(a) Write in-line code for string comparison to eliminate a procedure call.
(b) Store strings uniquely so that pointer comparison can be used.
(c) Call a library function for string comparison.
(d) Be sure to use hardware string-comparison instructions.
Correct answer is (b)
Your score on this question is: 0.00
Feedback:
See section 4.2.2 of the course notes.

-------------------------------------------------------------------------------2.
General wisdom, expressed by the 80/20 rule, says that
(a) algorithmic improvements account for the smallest amount of performance ga
in
(b) most execution time is spent in a small amount of code
(c) 80% of the execution time is in the user interface, and 20% does the real w
ork
(d) optimization can obtain between 20 and 80 percent improvement
Correct answer is (b)
Your score on this question is: 20.00
Feedback:
See section 4.2.1 of the course notes.
-------------------------------------------------------------------------------3.
In C and C++, which of the following functions allocate memory from the heap?
printf()
creating a new Standard Template Library string
cout << "Hello World"

(a) II only.
(b) I and II only.
(c) II and III only.
(d) I only.
Correct answer is (b)
Your score on this question is: 20.00

Feedback:
See section 4.3.1 of the course notes.
-------------------------------------------------------------------------------4.
A memory pool is a large block of memory from which small objects are allocated
piecemeal by breaking them off from the pool as required. Under which of the fo
llowing conditions would such a scheme result in greatly improved performance?
All objects allocated from the pool are freed at around the same time.
All objects allocated from the pool are of similar sizes.
A garbage collector takes care of freeing memory.

(a) III only.


(b) I only.
(c) II only.
(d) I and II only.
Correct answer is (b)
Your score on this question is: 20.00
Feedback:
See section 4.3.2 of the course notes.
-------------------------------------------------------------------------------5.
To quickly allocate and free many variables of a commonly used data type, we co
uld
(a) coalesce blocks when they are freed.
(b) keep a linked list of free objects of that type's size.
(c) minimize the size of the data type.
(d) use sizes which are powers of two.
Correct answer is (b)
Your score on this question is: 0.00
Feedback:
See section 4.3.2 of the course notes.
-------------------------------------------------------------------------------Go to top of assessment.
Total score: 60.00
? Copyright 2002 iCarnegie, Inc. All rights reserved.
View Assessment Result

Family Name: Han


Given Name: Lian
Login: nwpu043814
E-mail: october3rd@sina.com
Status: Active
Assessment Name: Multiple-Choice Quiz 14
Instance: 1
Section: NWPU-SSD6-2
During: Fall 2007
Section Status: Enrolled
For course: System-Level Programming
(SSD6)
Corresponding to: SSD6
At: Software College of Northwestern Polytechnical University
--------------------------------------------------------------------------------

Your performance was as follows:


You took 4 minutes on this assessment from Thu Jun 23 15:55:38 UTC+0800 2007 to
Thu Jun 23 15:59:33 UTC+0800 2007.
Total score: 80.00

1.
Compared to static RAM (SRAM), dynamic RAM (DRAM) is
more expensive per megabyte.
slower per word access.
more persistent.

(a) II only.
(b) II and III only.
(c) I only.
(d) I and III only.
Correct answer is (a)
Your score on this question is: 20.00
Feedback:
See section 5.1.1 of the course notes.

-------------------------------------------------------------------------------2.
Which of the following is necessarily true regarding the following code fragmen
t?
a = b;
c = d;
if (e == 1) return;

(a) It exhibits no locality of reference.


(b) It exhibits locality of reference but only when a == b.
(c) It exhibits locality of reference because the variables are allocated near
each other.
(d) It exhibits locality of reference no matter where the variables are allocat
ed.
Correct answer is (d)
Your score on this question is: 0.00
Feedback:
See section 5.1.2 of the course notes.
(c) There is nothing in the code above that forces the variables to be togeth
er.
-------------------------------------------------------------------------------3.
Which of the following levels of a typical memory hierarchy transfers data in c
hunks of smallest size?
(a) main memory <--> disk.
(b) cache <--> main memory.
(c) they all transfer one byte at a time.
(d) CPU registers <--> cache.
Correct answer is (d)
Your score on this question is: 20.00
Feedback:
See section 5.1.3 of the course notes.
-------------------------------------------------------------------------------4.
Which of the following manages the transfer of data between the cache and main
memory?
(a) Registry.
(b) Compiler.
(c) Hardware.

(d) Operating System.


Correct answer is (c)
Your score on this question is: 20.00
Feedback:
See section 5.1.3 of the course notes.
-------------------------------------------------------------------------------5.
Current technology trends suggest that the need for memory hierarchies
(a) will never disappear.
(b) will disappear when "broadband" communications start delivering data over t
he internet at speeds greater than 1Mbps.
(c) will disappear once processors reach clock frequencies greater than about 1
000MHz.
(d) will disappear once DRAM speeds improve.
Correct answer is (a)
Your score on this question is: 20.00
Feedback:
See section 5.1.3 of the course notes.
-------------------------------------------------------------------------------Go to top of assessment.
Total score: 80.00
? Copyright 2002 iCarnegie, Inc. All rights reserved.
View Assessment Result
View Assessment Result: Multiple-Choice Quiz 5

Your performance was as follows:


1.
Which of the following are effects of a page fault in the program that c
aused it by, e.g, reading the value of a variable?
An exception is thrown.
A delay occurs.
The program is terminated.

(a) I and III only


(b) II and III only
(c) II only

(d) I and II only


Correct answer is

(d)

Your score on this question is: 16.67


Feedback:
See section 5.3.2 of the course notes.
2.
Current technology trends suggest that the need for memory hierarchies

(a) will never disappear.


(b) will disappear when "broadband" communications start delivering data over t
he internet at speeds greater than 1Mbps.
(c) will disappear once processors reach clock frequencies greater than about 1
000MHz.
(d) will disappear once DRAM speeds improve.
Correct answer is

(a)

Your score on this question is: 16.67


Feedback:
See section 5.1.3 of the course notes.
3.
Compared to dynamic RAM (SRAM), disks are
more expensive per megabyte.
slower per word access.
more persistent.

(a) II only.
(b) II and III only.
(c) I and III only.
(d) I only.
Correct answer is

(b)

Your score on this question is: 16.67


Feedback:
See section 5.1.1 of the course notes.
4.
Compared to static RAM (SRAM), dynamic RAM (DRAM) is
more expensive per megabyte.
slower per word access.
more persistent.

(a) II only.

(b) II and III only.


(c) I only.
(d) I and III only.
Correct answer is

(a)

Your score on this question is: 16.67


Feedback:
See section 5.1.1 of the course notes.
5.
Your computer has 32-bit integers and a direct cache containing 128 32-b
yte cache lines. In the following code fragment, the compiler allocates a at add
ress 0x800000 and b at address 0x801000. Before the execution of the code fragme
nt, the arrays a and b have never been used, so they are not in the cache. What
is the minimum number of bytes from each of the arrays a and b that could be fet
ched into the cache from main memory, during the execution of the code?
int b[1024];
int a[1024];
for (i = 0; i < 17; sum += a[i] + b[i], i++);

(a) 1088
(b) 17
(c) 96
(d) 68
Correct answer is

(a)

Your score on this question is: 16.67


Feedback:
See section 5.2.1 of the course notes.
6.
Two computers A and B with a cache in the CPU chip differ only in that A
has an L2 cache and B does not. Which of the following are possible?
B executes a program more quickly than A.
A executes a program more quickly than B.
While executing a program, A fetches more data from main memory than does B.

(a) I, II and III.


(b) I and III only.
(c) II only.
(d) I and II only.
Correct answer is

(d)

Your score on this question is: 0.00


Feedback:
See section 5.2.2 of the course notes.

Go to top of assessment.
Total score: 83.33
? Copyright 2005 iCarnegie, Inc. All rights reserved.
Family Name: Han
Given Name: Lian
Login: nwpu043814
E-mail: october3rd@sina.com
Status: Active
Assessment Name: Multiple-Choice Quiz 15
Instance: 1
Section: NWPU-SSD6-2
During: Fall 2007
Section Status: Enrolled
For course: System-Level Programming
(SSD6)
Corresponding to: SSD6
At: Software College of Northwestern Polytechnical University
--------------------------------------------------------------------------------

Your performance was as follows:


You took 5 minutes on this assessment from Sun Jul 3 17:08:17 UTC+0800 2007 to
Sun Jul 3 17:13:15 UTC+0800 2007.
Total score: 0

1.
A program whose code and data together occupy fewer than 256 Kbytes is executed
on a computer with a 512 Kbyte direct cache. Which of the following is true?
(a) No bytes will be fetched from main memory
(b) There is no telling, from the information given, how many bytes will be fet
ched from main memory.
(c) Some bytes, but at most 256 Kbytes, will be fetched from main memory.
(d) Every instruction fetch will cause a cache miss.
Correct answer is (b)
Your score on this question is: 0.00
Feedback:
See section 5.2.1 of the course notes.

-------------------------------------------------------------------------------2.
Which facts about the cache can be determined by calling the following function
?
int data[1 << 20];
void callee(int x) {
int i, result;
for (i = 0; i < (1 << 20); i += x) {
result += data[i];
}
}
cache line size
cache size
cache speed

(a) I and III only


(b) I and II only
(c) I, II, and III
(d) I only
Correct answer is (d)
Your score on this question is: 0.00
Feedback:
See section 5.2.3 of the course notes.
(a) If the cache line size equals the size of an integer, the code above neve
r has a cache hit.
-------------------------------------------------------------------------------3.
Consider the following fragments from two versions of a program. Version A Ver
sion B
for (i = 0 ; i < N ; i++ ) {
Read(i);
Calculate(i);
Write(i);
}
for (i = 0 ; i < N ; i++ ) {
Read(i);
}
for (i = 0 ; i < N ; i++ ) {
Calculate(i);
}
for (i = 0 ; i < N ; i++ ) {
Write(i);
}
}

Which
B may
B may
B may

of the following are true of version B, compared to version A?


be faster because of cache effects.
be slower because of cache effects.
execute at essentially the same speed as A.

(a) I only
(b) I and III only
(c) II and III only
(d) I, II, and III
Correct answer is (d)
Your score on this question is: 0.00
Feedback:
See section 5.2.4 of the course notes.
-------------------------------------------------------------------------------Go to top of assessment.
Total score: 0
? Copyright 2002 iCarnegie, Inc. All rights reserved.
View Assessment Result

Family Name: Han


Given Name: Lian
Login: nwpu043814
E-mail: october3rd@sina.com
Status: Active
Assessment Name: Multiple-Choice Quiz 15
Instance: 2
Section: NWPU-SSD6-2
During: Fall 2007
Section Status: Enrolled
For course: System-Level Programming
(SSD6)
Corresponding to: SSD6
At: Software College of Northwestern Polytechnical University
--------------------------------------------------------------------------------

Your performance was as follows:

You took 2 minutes on this assessment from Sun Jul 3 17:14:29 UTC+0800 2007 to
Sun Jul 3 17:15:51 UTC+0800 2007.
Total score: 66.67

1.
When the following code fragment is executed on a computer with 32-bit integers
and a fully-associative cache with 32-byte cache lines, how many bytes of the a
rray a will be fetched into the cache from main memory?
int a[100];
for (i = 0; i < 17; sum += a[i], i++);

(a) at most 68.


(b) exactly 17.
(c) exactly 32.
(d) at most 96.
Correct answer is (d)
Your score on this question is: 0.00
Feedback:
See section 5.2.1 of the course notes.

-------------------------------------------------------------------------------2.
Which facts about the cache can be determined by calling the following function
?
int data[1 << 20];
void callee(int x) {
int i, result;
for (i = 0; i < (1 << 20); i += x) {
result += data[i];
}
}
cache line size
cache size
cache speed

(a) I, II, and III


(b) I only
(c) I and II only
(d) I and III only
Correct answer is (b)

Your score on this question is: 33.33


Feedback:
See section 5.2.3 of the course notes.
-------------------------------------------------------------------------------3.
Consider the following fragments from two versions of a program. Version A Ver
sion B
for (i = 0 ; i < N ; i++ ) {
Read(i);
Calculate(i);
Write(i);
}
for (i = 0 ; i < N ; i++ ) {
Read(i);
}
for (i = 0 ; i < N ; i++ ) {
Calculate(i);
}
for (i = 0 ; i < N ; i++ ) {
Write(i);
}
}
Which
B may
B may
B may

of the following are true of version B, compared to version A?


be faster because of cache effects.
be slower because of cache effects.
execute at essentially the same speed as A.

(a) I only
(b) I and III only
(c) I, II, and III
(d) II and III only
Correct answer is (c)
Your score on this question is: 33.33
Feedback:
See section 5.2.4 of the course notes.
-------------------------------------------------------------------------------Go to top of assessment.
Total score: 66.67
? Copyright 2002 iCarnegie, Inc. All rights reserved.
View Assessment Result

Family Name: Han


Given Name: Lian
Login: nwpu043814
E-mail: october3rd@sina.com
Status: Active
Assessment Name: Multiple-Choice Quiz 16
Instance: 1
Section: NWPU-SSD6-2
During: Fall 2007
Section Status: Enrolled
For course: System-Level Programming
(SSD6)
Corresponding to: SSD6
At: Software College of Northwestern Polytechnical University
--------------------------------------------------------------------------------

Your performance was as follows:


You took 2 minutes on this assessment from Sun Jul 3 17:16:20 UTC+0800 2007 to
Sun Jul 3 17:17:56 UTC+0800 2007.
Total score: 20.00

1.
Which of the following is a shortcoming (are shortcomings) of segmented virtual
memory, compared to paged virtual memory?
It causes external fragmentation.
It causes internal fragmentation.
It requires program relocation.

(a) II and III only


(b) I only
(c) I and III only
(d) II only
Correct answer is (b)
Your score on this question is: 0.00
Feedback:
See section 5.3.1 of the course notes.

-------------------------------------------------------------------------------2.
Two variables of a program are found to be allocated to virtual addresses 0x800
000 and 0xA00000 respectively. The program is then executed on a computer that u
ses paged virtual memory with a page size of 8 KB (0x2000 B). Which of the follo
wing are necessarily true?
The program occupies more than 256 pages of physical memory.
The program occupies more than 2 MB of physical memory.
The program occupies more than 10 MB of physical memory.

(a) I and II only


(b) None
(c) III only
(d) I, II, and III
Correct answer is (b)
Your score on this question is: 0.00
Feedback:
See section 5.3.1 of the course notes.
-------------------------------------------------------------------------------3.
A program cannot accidentally "crash" a computer that uses
virtual memory addresses
program relocation
separate instruction and data caches.

(a) I and II only


(b) II and III only
(c) III only
(d) I only
Correct answer is (d)
Your score on this question is: 0.00
Feedback:
See section 5.3.1 of the course notes.
-------------------------------------------------------------------------------4.
Which of the following are effects of a page fault in a program? Assume that th
e page fault is caused by the program by reading the value of a variable that be
longs to the program, and that the variable is in an unmapped page.
A hardware exception is thrown and handled by the operating system.
A delay occurs.
An exception is thrown that should be handled by the program's source code or th
e program will terminate.

(a) I and III only


(b) II only
(c) II and III only
(d) I and II only
Correct answer is (d)
Your score on this question is: 0.00
Feedback:
See section 5.3.2 of the course notes.
-------------------------------------------------------------------------------5.
The working set of a program is formed by
(a) the memory of the program that is currently in physical memory
(b) the libraries required by the program
(c) the pages that the program is actively using
(d) all the files the program needs to execute
Correct answer is (c)
Your score on this question is: 20.00
Feedback:
See section 5.3.3 of the course notes.
-------------------------------------------------------------------------------Go to top of assessment.
Total score: 20.00
? Copyright 2002 iCarnegie, Inc. All rights reserved.
View Assessment Result

Family Name: Han


Given Name: Lian
Login: nwpu043814
E-mail: october3rd@sina.com
Status: Active
Assessment Name: Multiple-Choice Quiz 16
Instance: 2
Section: NWPU-SSD6-2
During: Fall 2007
Section Status: Enrolled

For course: System-Level Programming


(SSD6)
Corresponding to: SSD6
At: Software College of Northwestern Polytechnical University
--------------------------------------------------------------------------------

Your performance was as follows:


You took 3 minutes on this assessment from Sun Jul 3 17:18:40 UTC+0800 2007 to
Sun Jul 3 17:20:53 UTC+0800 2007.
Total score: 100.00

1.
Which of the following is a shortcoming (are shortcomings) of segmented virtual
memory, compared to paged virtual memory?
It causes external fragmentation.
It causes internal fragmentation.
It requires program relocation.

(a) II only
(b) I only
(c) I and III only
(d) II and III only
Correct answer is (b)
Your score on this question is: 20.00
Feedback:
See section 5.3.1 of the course notes.

-------------------------------------------------------------------------------2.
A program cannot accidentally "crash" a computer that uses
virtual memory addresses
program relocation
separate instruction and data caches.

(a) I and II only


(b) I only
(c) II and III only

(d) III only


Correct answer is (b)
Your score on this question is: 20.00
Feedback:
See section 5.3.1 of the course notes.
-------------------------------------------------------------------------------3.
Two variables of a program are found to be allocated to virtual addresses 0x800
000 and 0xA00000 respectively. The program is then executed on a computer that u
ses paged virtual memory with a page size of 8 KB (0x2000 B). Which of the follo
wing are necessarily true?
The program occupies more than 256 pages of physical memory.
The program occupies more than 2 MB of physical memory.
The program occupies more than 10 MB of physical memory.

(a) None
(b) III only
(c) I, II, and III
(d) I and II only
Correct answer is (a)
Your score on this question is: 20.00
Feedback:
See section 5.3.1 of the course notes.
-------------------------------------------------------------------------------4.
Which of the following are effects of a page fault in a program? Assume that th
e page fault is caused by the program by reading the value of a variable that be
longs to the program, and that the variable is in an unmapped page.
A hardware exception is thrown and handled by the operating system.
A delay occurs.
An exception is thrown that should be handled by the program's source code or th
e program will terminate.

(a) II and III only


(b) I and II only
(c) II only
(d) I and III only
Correct answer is (b)
Your score on this question is: 20.00
Feedback:
See section 5.3.2 of the course notes.

-------------------------------------------------------------------------------5.
The working set of a program is formed by
(a) the pages that the program is actively using
(b) the memory of the program that is currently in physical memory
(c) the libraries required by the program
(d) all the files the program needs to execute
Correct answer is (a)
Your score on this question is: 20.00
Feedback:
See section 5.3.3 of the course notes.
-------------------------------------------------------------------------------Go to top of assessment.
Total score: 100.00
? Copyright 2002 iCarnegie, Inc. All rights reserved.
View Assessment Result

Family Name: Han


Given Name: Lian
Login: nwpu043814
E-mail: october3rd@sina.com
Status: Active
Assessment Name: Multiple-Choice Quiz 17
Instance: 1
Section: NWPU-SSD6-2
During: Fall 2007
Section Status: Enrolled
For course: System-Level Programming
(SSD6)
Corresponding to: SSD6
At: Software College of Northwestern Polytechnical University
--------------------------------------------------------------------------------

Your performance was as follows:

You took 6 minutes on this assessment from Thu Jun 23 17:41:50 UTC+0800 2007 to
Thu Jun 23 17:47:29 UTC+0800 2007.
Total score: 100.00

1.
Time-sharing occurs when
(a) clocks are properly synchronized in a network of computers.
(b) one program must terminate before the next program can run.
(c) more than one program executes concurrently on a single computer.
(d) there is not enough memory to run all the applications that have been start
ed.
Correct answer is (c)
Your score on this question is: 20.00
Feedback:
See section 6.2.1 of the course notes.

-------------------------------------------------------------------------------2.
Polling is undesirable in a time-shared operating system because
(a) it wastes time that could be used to do useful work.
(b) it is too complicated to implement
(c) it leads to interference between two applications accessing the same resour
ce.
(d) it makes programs much larger.
Correct answer is (a)
Your score on this question is: 20.00
Feedback:
See section 6.2.2 of the course notes.
-------------------------------------------------------------------------------3.
To restrict access to an input/output device in a time-shared system, a program
has to
(a) execute special I/O instructions in the application's address space.
(b) present the addresses of the device registers to the operating system.
(c) make a system call through a trap instruction.
(d) map the device control registers into the application's address space.

Correct answer is (c)


Your score on this question is: 20.00
Feedback:
See section 6.2.2 of the course notes.
-------------------------------------------------------------------------------4.
A context switch occurs when
(a) a modal dialog box is created.
(b) the system starts executing a different process.
(c) an operating system goes into standby mode.
(d) a new stack frame (activation record) is created.
Correct answer is (b)
Your score on this question is: 20.00
Feedback:
See section 6.2.3 of the course notes.
-------------------------------------------------------------------------------5.
When a context switch occurs,
(a) the contents of the cache are mostly irrelevant.
(b) the cache must be disabled.
(c) the cache contents must be saved along with the processor registers.
(d) the contents of the cache are vital for performance.
Correct answer is (a)
Your score on this question is: 20.00
Feedback:
See section 6.2.3 of the course notes.
-------------------------------------------------------------------------------Go to top of assessment.
Total score: 100.00
? Copyright 2002 iCarnegie, Inc. All rights reserved.
View Assessment Result

Family Name: Han


Given Name: Lian
Login: nwpu043814
E-mail: october3rd@sina.com
Status: Active
Assessment Name: Multiple-Choice Quiz 18
Instance: 1
Section: NWPU-SSD6-2
During: Fall 2007
Section Status: Enrolled
For course: System-Level Programming
(SSD6)
Corresponding to: SSD6
At: Software College of Northwestern Polytechnical University
--------------------------------------------------------------------------------

Your performance was as follows:


You took 3 minutes on this assessment from Tue Jun 28 12:12:05 UTC+0800 2007 to
Tue Jun 28 12:14:18 UTC+0800 2007.
Total score: 100.00

1.
Threads differ from processes in that threads
(a) cannot make system calls.
(b) share a single virtual address space.
(c) exist only in the operating system kernel.
(d) cannot be preempted.
Correct answer is (b)
Your score on this question is: 20.00
Feedback:
See section 6.3.1 of the course notes.

-------------------------------------------------------------------------------2.
For which of the following applications are threads well suited?
Background processing such as data compression or spell-checking
Displaying a web page on the screen before it has fully arrived from the server

Fetching a page of a web document while the user scrolls through the previous on
e

(a) I only
(b) I, II, and III
(c) I and II only
(d) II only
Correct answer is (b)
Your score on this question is: 20.00
Feedback:
See section 6.3.2 of the course notes.
-------------------------------------------------------------------------------3.
A reentrant function can be entered
(a) concurrently by more than one thread
(b) at several points, not only the top
(c) multiple times but only by one thread at a time
(d) only once before variables are reinitialized
Correct answer is (a)
Your score on this question is: 20.00
Feedback:
See section 6.3.3 of the course notes.
-------------------------------------------------------------------------------4.
A lock is a software mechanism that
(a) implements password protection to data.
(b) limits access to a critical section.
(c) temporarily makes memory read-only.
(d) prevents execution except in debug mode.
Correct answer is (b)
Your score on this question is: 20.00
Feedback:
See section 6.3.4 of the course notes.
-------------------------------------------------------------------------------5.
Priority inversion is a situation in which

(a) the scheduler reverses priorities to prevent starvation of low-priority th


reads.
(b) long-running processes are assigned lower priorities.
(c) a high-priority thread indirectly waits on a lower priority thread.
(d) threads with the earliest deadlines receive higher priorities.
Correct answer is (c)
Your score on this question is: 20.00
Feedback:
See section 6.3.5 of the course notes.
-------------------------------------------------------------------------------Go to top of assessment.
Total score: 100.00
? Copyright 2002 iCarnegie, Inc. All rights reserved.
4.
Amdahl's law, applied to program optimization, says that
(a) program measurement is a prerequisite to optimization
(b) algorithmic design is more important than code quality for performance
(c) successive program optimizations tend to produce diminishing returns
(d) each optimization about doubles a program's performance
Correct answer is (c)
When a cache is full and a new cache line needs to be fetched into it, which of
the following is a pretty good, practical approach?
(a) choosing the cache location currently occupied by the least-recently-used
data.
(b) choosing always the same cache location for the new line.
(c) randomly selecting a cache location for the new line.
(d) denying the memory operation that caused the fetch of the new line.
Correct answer is (c)
3.
Which of the following manages the transfer of data between the CPU registers a
nd the cache?
(a) Registry.
(b) Compiler.
(c) Operating System.
(d) Hardware.
Correct answer is (b)

Your score on this question is: 0.00

Potrebbero piacerti anche