系统级编程选择题

Multiple Choice Quiz 1
1. Which of t he following Visual C++ objects are
contained within a "Project"? (a)
I. Files II. Visual C++ Solutions III.
Flow charts
a. I only
b. I, II and III
c. II only
d. II and III only
Which is the start point of a Windows program (d)
a. the status window of the Visual C++
environment
b. built by using sophisticated "Application
Wizards"
c. a program that is able to control the operating
system of a windows computer
d. the simplest type of application Visual C++ can
generate
3. Which of the following is able to describe a
computation at the highest level of abstraction? (a)
a. C++ code
b. logic Gates
c. machine code
d. C code
4. Consider the following fragment of C++ source
code. (c)
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?
1. The input statement will always take the
same amount of time to execute.
2. The output statement will always be
executed immediately after the input statement.
3. If x and y are both positive, an integer
greater than both will be printed.
a. II and III only
b. I and II only
c. none
d. II only
5. Integrated programming environments make it
difficult to mix and match tools from different
sources. This is (b)
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 tools
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
6. Compared to a sequence of machine code
instructions, a fragment of C code (a)
a. may describe the same algorithm
b. is the native way to program most computers
c. describes the actions of the computer, not just
of the CPU
d. does not engage any transistors during its
execution
7. Which of the following does a debugger do?
(c)
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. I and III only
c. II and III only
d. III only
8. When using a debugger to find the cause of a
program's incorrect behavior, (a)
a. it is often necessary to start the program
multiple times under the debugger
b. the faulty code fragment must first be identified
c. the program is usually executed to the point at
which the behavior occurs and then executed
backwards to find the cause
d. it is fastest to start by stopping the debugger
long before the behavior appears
Multiple Choice Quiz 2
1. In a computer with 4-byte words, which of the
following C expressions tests whether ptr contains
the address of a word? (c)
I. (ptr & 3) == 0
II. (ptr | 3) == 0
III. (ptr % 4) == 0
a. III only
b. I only
c. I and III only
d. II only
2. What happens in a C program when an addition
would cause integer overflow? (a)
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.
3. In C, what is the following binary number in
hexadecimal? (a)
11010101
a. 0xD5
b. 0x5D
c. 0xB5
d. 0xAB
4. What is the purpose of the exponent in floating
point numbers? (c)
a. to specify the base as binary, octal, or
hexadecimal
b. the mantissa is raised to the power of the
exponent
c. to indicate where the decimal or binary point
should be
d. to specify the superscript
5. How is -10 (decimal) represented in an 8-bit 2's
complement binary format? (a)
a. 11110110
b. 11110101
c. 10001010
d. 11111010
6. In C, using default floating point settings, what
happens when a floating-point computation results
in an overflow? (c)
a. An erroneous value is computed and execution
continues.
b. Program execution is halted.
c. A special value "infinity" is computed, testable
with _finite().
d. An exception is raised unless disabled by calling
_controlfp().
7. What is the value of the following C expression?
(c)
0x1234 & 0x5432
a. 0x1111
b. 0x6666
c. 0x1030
d. 0x5636
8. Which of the following numerical operations is
most likely to lead to loss of precision? (c)
a. Floating-point multiplication
b. Integer addition
c. Floating-point addition
d. Integer multiplication
9. Which of the following could be represented by
one bit of information? (c)
a. the color of a single pixel on a true-color
computer display
b. an ASCII character
c. the position of a light switch
d. the current channel of a television receiver
10. Which of the following statements about
floating-point numbers in C is true? (a)
I. Floating-point numbers are often only
approximations of real numbers.
II. A 32-bit float only approximates decimal
fractions, but a 64-bit double represents them
exactly.
III. Floating-point numbers can represent any
rational real number but not irrationals.
a. I only
b. I and III only
c. II only
d. I and II only
11. How is 46 (decimal) represented in an 8-bit 2's
complement binary format? (a)
a. 00101110
b. 01000110
c. 00011110
d. 00101100
12. What is the value of the following C expression?
(d)
0x1234 ^ 0x5432 (这是XOR运算)
a. 0x1030
b. 0x5434
c. 0x5636
d. 0x4606
Multiple Choice Quiz 3
1:The program counter contains (D)
a. the number of CPU instructions a program
has executed so far
b. the number of times a program has been
executed
c. the amount of memory a program is
currently using
d. the address of the CPU instruction that is
about to be fetched
2: Which of the following is a good reason (are
good reasons) to equip the CPU with small
amounts of fast memory? (a)
I.To make the design of the compiler simpler

II.To make some CPU instructions smaller
III.To make some CPU instructions faster
a. II and III only
b. I, II, and III
c. III only
d. II only
3. Which of the following must be true if a
program is stopped at a specific line within the
Visual C++ debugger? (D)
I. There is at least one breakpoint enabled.
II. There is a breakpoint enabled on that line.
III. 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
4: Programs compiled for an Intel Pentium
processor do not execute properly on
a SPARC processor from Sun Microsystems because
(B)
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 processors
d. the memory of a SPARC CPU is numbered from
top to bottom
5: Within Visual C++, which of the following will
reveal the value of variable when the program is
stopped at a breakpoint? (B)
I. Placing the mouse pointer over the variable
name in the source file window.
II. Inserting a printf() in the program.
III. 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
6: Immediately after the CPU executes an
instruction that is neither a branch
nor a jump instruction, the program counter (B)
a. remains unchanged
b. is incremented to point to the following
instruction
c. has a value that cannot be determined without
further information
d. is incremented by one
7: A CPU register is a word of CPU memory that
(C)
a. houses a critical variable for the duration of the
execution of a program
b. records the results of periodic CPU diagnostics
c. is explicitly loaded and unloaded from normal
memory by compiler-generated instructions
d. is automatically loaded when a CPU instruction
refers to a word of normal memory
8: Which of the following computations may be
performed by exactly one CPU instruction? (A)
1. a = 5;
2. a = b + c * 5;
3. for (i = 0; i < 10; i += a[i++]);
a. I only
b. II only
c. I, II, and III
d. I and II only
9: Suppose that, using a tool such as the memory
window of Visual C++, we found that a certain set
of contiguous memory locations contained the
integer 0xC605CD623A8365000000. What could
these memory locations hold? (D)
1. the integer 0xC605CD623A8365000000
2. a string
3. a CPU instruction
a. I only
b. III only
c. I and II only
d. I, II, and III
10: A branch instruction (A)
a. sets the program counter to one of two possible
values
b. increases the program counter by a fixed
amount
c. sets the program counter to one of many
possible values
d. unconditionally sets the program counter to its
operand
11:A jump instruction (D)
a. changes the program counter only if its operand
is equal to zero
b. changes a pointer to point to the next element
of an array
c. increases the program counter
d. unconditionally sets the program counter to its
operand

code by a compiler (C)
a. associates variable values with their names
b. executes more quickly than the source code
c. does not preserve all the information given in
the source code
d. can be easily inspected to check the correctness
of the compiler
13: Which of the following are true of the effect
that optimizations have on the machine code
generated by compilers? (B)
I. The resulting code will be faster and/or smaller.
II. The resulting code will be clearer.
III. The resulting code will be harder to debug.
a. I, II, and III
b. I and III only
c. I and II only
d. I only
Multiple Choice Quiz 4
1:In C, assuming that an int takes 4 bytes, if array
a is declared as follows and a has the value
0x10000, what is the value of the expression
a + 2? (D) (a是array 的首地址)
int a[12];
a. 0x10004
b. 8 plus the contents of location 0x10000
c. 0x10002
d. 0x10008
2:The Visual C++ Memory window displays (A)
a. the contents of memory, interpreted in one of
several ways, without the associated variable
names
b. the names and values of variables in memory,
interpreted in one of several ways
c. the names and values of variables in memory,
interpreted as 32-bit integers no matter what the
variables' types
d. the contents of memory, interpreted as 32-bit
integers, without the associated variable names
3: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? (B)
a. The value of *d is closer to the value of *c than
to the value of *a.
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 values of &a and &b are closer to each
other than the values of &c and &d.
4: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. a[4]
b. the integer stored in the bytes a[4], a[5], a[6]
and a[7]
c. a[3]
d. a[0] + 4
5:Which of the following statements about
alignment within C struct's is true? ( D)
I. Alignment may cause the allocation of unused
space.
II. Alignment is required by all modern processors.
III. Alignment can help processors access data
more efficiently.
a. I, II, and III
b. I only
c. II and III only
d. I and III only
6:In C, assuming that an int takes 4 bytes, how
many bytes are required
to represent the following array? ( C)
int a[12];
a. 12
b. 52
c. 48
d. 44
7:Given the following declaration and
initialization of s, what is the
value of the expression s[6]? (D)
char s[] = "string";
a. '\n'

b. an unpredictable value
c. 'g'
d. '\0'
8:Given the address of a C struct at runtime, how
is the address of a member element in the struct
determined? (C)
a. A linear search is made from the base address
of the struct.
b. The element name is looked up in a symbol
table.
c. A constant offset associated with the member is
added to the address.
d. The struct consists of an array of pointers to the
elements of the struct.
9:In one computer, the bytes with addresses A,
A+1, A+2 and A+3 contain the integer 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 following are necessarily true? (A)
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. III only
b. I only
c. II and III only
d. I and III only
10:We want the variable factorialfunc to hold the
address of the first instruction of the following
function: (B)
int factorial(int n) {
if (n == 1) return n;
return n * factorial(n -1);
}
How would we declare the variable?
a. int (int) * factorialfunc
b. int (*factorialfunc)(int);
c. factorial() * factorialfunc;
d. we can't: C cannot extract the addresses of
instructions.
Multiple Choice Quiz 5
1: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)
a. Two different integers are printed, and the
value of neither can be determined from the
information given.
b. One integer is printed twice, and its value
cannot be determined from the information given.
c. 5 is printed twice on the same line.
d. 5 and 4 are printed, in that order on the same
line.
2: What does the following program print? (D)
int callee(int * count) {
count++;
return *count;
}
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; }
3: At which of the following times is an activation
record created? (C)
I. When a program starts executing.
II.Every time a function is invoked.
III.When a variable is declared.
a. 8
b. 4
c. 5
d. cannot be determined from the information
given.

a. III only
b. II only
c. I and II only
d. II and III only
4: What does the following program print? (D)
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
5: 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 (C)
a. just one address, and it is not known to the
compiler
b. just one address, and it was chosen by the
compiler
c. many addresses none of which is known to the
compiler
d. many addresses that were chosen by the
compiler
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? (D)
a. i, j and number only.
b. i only.
c. plusone only.
d. plusone and number only.
7: Consider the following program. (C)
int i;
int * jp = &i;
void main(int i, char * argv[]) {
printf("%d %d\n", (int) &i, (int) jp);
}
Which of the following describes what it prints?
a. two values, one 4 greater than the other
b. nothing: it will not compile because it is
ambiguous
c. two very different integers
d. two integers that are exactly the same
8: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)
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 compile
9: What is printed as a result of execution of the
following program?( B)
#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. 5
c. 4
d. It cannot be determined from the information
given.
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? (B)
a. &a
b. a
c. (int) &a
d. (int) &b
11:In one computer, the bytes with addresses A,
A+1, A+2 and A+3 contain the integer 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.
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? (C)
int a;
int * b = &a;
a. 0
b. 32
c. 8
d. 4
12: Activation records are organized in stacks
because (B)
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.
13: When executing a function callee(), which of
the following are true regarding the value of the
frame pointer? (B)
I. It marks the top of the stack frame of the
function that invoked callee().
II. It marks the bottom of the stack frame of callee()
III. It is the top of the stack.
a. II only
b. I and II only
c. I only
d. III only
14: 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 factorial(4)? (C)
a. 0
b. 5
c. 4
d. 1
Multiple Choice Quiz 6
1: Which of the following are true about statically
allocated data in C programs? (B)
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 table.
a. III only.
b. I only.
c. II and III only.
d. I and II only.
2: A memory leak is caused by a (D)
a. function that allocates a large amount of
memory from the heap
b. bug in which too much memory is allocated,
causing internal fragmentation
c. bug in the memory allocator that fails to free
memory
d. failure to free allocated memory
3: In C, local variables allocated inside functions are
allocated (B)
a. in a fifo
b. on the stack
c. in static storage
d. in the heap
4: Suppose a compiler uses static storage to store
all variables, function parameters, saved registers,
and return addresses. Which of the following
language features can this compiler support? (C)
I. Local variables.
II. Function calls.
III. Recursion.
a. I only
b. II only

c. I and II only
d. I, II, and III
5:The key feature of implicit memory
management is that memory is freed automatically.
Which of the following features of C make(s) it
difficult to add support for implicit memory
management in C? (C)
I.Pointers are not always initialized.
II.Type casting makes it impossible to know when a
value could be a pointer.
III. C programs can allocate memory at runtime.
a. II only
b. III only
c. I and II only
d. I only
6:Which of the following features apply to
standard heap allocation in C?( D)
I.The size of heap objects must be known at
compile time.
II.Heap memory must be explicitly allocated.
III.Heap memory is deallocated when a function
returns.
a. I only.
b. I and II only.
c. I and III.
d. II only.
7:In this sequence of C statements ( C)
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;
8.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?
I.p and q are identical pointers to freed storage.
II.p points to freed storage, and q points to an
allocated block of size 100.
III.p should not be free()d again, but invoking
free(q) is all right. ( B)
a. II only
b. I only
c. III only
d. II and III only
9:In C, to allocate an array of 100 longs on the
heap you should write (C)
a. long a[] = (long *) malloc(100);
b. long *a = (long *) malloc(100);
c. long *a = (long *) malloc(100 * sizeof(long));
d. long a[100] = (long *) malloc(sizeof(a));
10:What is the value of an uninitialized pointer
variable declared within a function? (C)
a. its last value from the previous call to the
function
b. 0xDEADBEEF
c. the value is undefined
d. 0 (or NULL)
11:Consider a system in which memory consists of
the following hole sizes in memory order:
H0 H1 H2 H3 H4 H5 H6 H7
10K 4KB 20KB 18KB 7KB 9KB 12KB 15KB
and a successive segment request of
a) 12 KB
b) 10KB
c) 9KB
Which of the following sentences is true? (D)
I. First Fit algorithm allocates H2, H0, H3 for the
mentioned request.
II. Worst Fit algorithm allocates H2, H3, H7 for the
mentioned request.
III. Best Fit algorithm allocates H6, H0, H5 for the
mentioned request.
a. I and III only
b. II only
c. II and III only
d. I, II, and III
12:Consider the malloc() function. Which one of
the following sentences is correct? ( D)
a. The malloc() returns the amount of memory
allocated
b. The malloc() allocates the desired amount of
memory on the stack
c. The allocated memory is only local to the
function
d. The malloc() allocates the desired amount of
memory on the heap
Multiple Choice Quiz 7
1. What properties of a variable are specified by
the static keyword in C?
I. The variable will be statically allocated.
II. The variable name will be visible only to
functions defined within the same file.
III. The variable's value does not change very often.

The compiler uses this fact to focus optimizations
on other variables. (d)
a. III only
b. I and III only
c. I only
d. I and II only
2 what will be the output?
#include <stdio.h>
void main(){
char *p="Hello world!";
int *q;
p++;
q = (int *)p;
q++;
printf("%s%s\n",p,q);
} (a)
a. ello world! world!
b. ello world!llo world!
c. Hello world!Hello world!
d. Error
3. To resolve memory leaks in C, one common
approach is: (c)
a. to ensure that memory blocks are allocated only
on word boundaries.
b. to add padding before and after allocated
memory blocks and to fill that memory with a
known value.
c. to check whether the number of calls to malloc()
is greater than the number of calls to free().
d. to store the source code line whence each block
is allocated.
4. 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?
I. p and q are identical pointers to freed storage.
II. p points to freed storage, and q points to an
allocated block of size 100.
III. p should not be free()d again, but invoking
free(q) is all right. (a)
a. I only
b. II and III only
c. III only
d. II only
5. A static variable by default gets initialized to
(c)
a. garbage value
b. blank space
c. 0
d. 1
6. The C expression a->b is equivalent to (b)
a. *(a + b)
b. (*a).b
c. (&a).b
d. (&a) + b
7. In C, when a struct is freed, (d)
a. only those pointers within the struct that point
into the heap are freed automatically.
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.
8. In C, which of the following is the best way to
detect when a pointer is freed twice? (a)
a. Flag all blocks as free or not, and check the flag
when calling free().
b. Set pointers to NULL after freeing them.
c. Modify free() to set the freed data to zero.
d. Keep a log of addresses that have been freed
and scan the log before calling free().
9. In C, calloc() differs from malloc() in that calloc():
(b)
a. is faster.
b. sets the contents of the block to zero before
returning.
c. allocates additional memory from the stack.
d. detects memory allocation errors.
10. A memory leak is caused by a: (d)
a. bug in which too much memory is allocated,
causing internal fragmentation
b. bug in the memory allocator that fails to free
memory
c. function that allocates a large amount of
memory from the heap
d. failure to free allocated memory
11. Why is it wrong to return the address of a local
variable? (c)
a. The local variable may be in a machine register.
b. It allows illegal access to the variable from
arbitrary functions.
c. The variable address is invalid after the return.
d. It is faster to return the value of the variable.
Multiple Choice Quiz 8
1:How does JAVA handle memory allocation? (A)

a. JAVA always uses a garbage collector.
b. JAVA has a garbage collector that can be used
or turned off.
c. Allocation and deallocation is the responsibility
of the programmer.
d. Allocation and deallocation is completely
shielded from the programmer.
2:A garbage collector (A)
a. frees memory blocks that cannot be reached by
dereferencing pointers.
b. removes old versions of local variables from the
stack .
c. frees memory blocks marked as "deleteable".
d. frees all memory blocks that will not be
accessed in the future.
3: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 following conditions would
such a scheme result in greatly improved
performance? (A)
I. All objects allocated from the pool are freed at
around the same time.
II. All objects allocated from the pool are of similar
sizes.
III. A garbage collector takes care of freeing
memory.
a. I only.
b. II only.
c. III only.
d. I and II only.
4:Reference counts used in implementations of
garbage collectors count (C)
a. the number of times a block has been allocated.
b. the number of times a block has been accessed.
c. the number of pointers pointing to a block.
d. the number of times a datum has been
referenced inside each block.
5:To quickly allocate and free many variables of a
commonly used data type, we could (C)
a. coalesce blocks when they are freed.
b. use sizes which are powers of two.
c. keep a linked list of free objects of that type's
size.
d. minimize the size of the data type.
Multiple Choice Quiz 9
1. Which of the following are useful for observing
program performance?
I. Direct measurement with a stopwatch.
II. Statistical Sampling.
III. System Monitors (d)
a. I and III only
b. I and II only
c. II and III only
d. I, II, and III
2. Which of the following approaches towards
optimizing programs is most advisable? (b)
a. "Optimize as you go": make sure every function
is optimized before writing the next one.
b. Optimize after all functions are written and
debugged.
c. Optimize main() first.
d. Optimize the more complex functions first. You
did not answer this question. Correct answer is
3. Which of the following is likely to offer the best
performance improvement for programs that
spend 50% of their time comparing strings? (a)
a. Store strings uniquely so that pointer
comparison can be used.
b. Be sure to use hardware string-comparison
instructions.
c. Write in-line code for string comparison to
eliminate a procedure call.
d. Call a library function for string comparison.
4. In the process of Software Optimization Process,
what should do first? (b)
a. Investigate causes of Hotspots
b. find the Hotspots
c. Modify application.
d. think of better Algorithm or using better Data
structure
5. "Wall time" measures (b)
a. idle time.
b. the total duration of a program's execution.
c. the time a program spends waiting for input and
output.
d. the user time plus the system time.
6. What is TSC? (c)
a. A timer mechanism of OS
b. A system call of OS
c. A timer mechanism of x86 platform, which is the
shortname of Time stamp counter
d. A timer mechanism of C library
7. "CPU time" measures (b)
a. the time spent executing system functions.

b. the time spent by a program executing program
instructions
c. wall time
d. the percentage utilization of the CPU by the
system.
8. Which is a function call of C library? (a)
a. Clock()
b. SetTimer
c. gettimeofday()
d. GetLocalTime
9. Which of the following are advantages of using
statistical sampling to profile programs? (a)
I. Exact run times of all functions can be
determined.
II. Code can be instrumented automatically.
III. The performance impact due to measurement
can be minimal.
a. II and III only
b. I and II only
c. I and III only
d. I, II, and III
10. Amdahl's law, applied to program optimization,
says that (d)
a. each optimization about doubles a program's
performance
b. program measurement is a prerequisite to
optimization
c. algorithmic design is more important than code
quality for performance
d. successive program optimizations tend to
produce diminishing returns
11. General wisdom, expressed by the 80/20 rule,
says that (c)
a. 80% of the execution time is in the user interface,
and 20% does the real work
b. algorithmic improvements account for the
smallest amount of performance gain
c. most execution time is spent in a small amount
of code
d. optimization can obtain between 20 and 80
percent improvement
Multiple Choice Quiz 10
1. Which of the following is likely to offer the best
performance improvement for programs that
spend 50% of their time comparing strings? (b)
a. Be sure to use hardware string-comparison
instructions.
b. Store strings uniquely so that pointer
comparison can be used.
c. Write in-line code for string comparison to
eliminate a procedure call.
d. Call a library function for string comparison.
2. Read the following code, and how can we
optimize it? (c)
void lower1(char *s)
{
int i;
for (i = 0; i < strlen(s); i++)
if (s[i] >= 'A' && s[i] <= 'Z')
s[i] -= ('A' - 'a');
}
a. Enhancing Parallelism
b. Loop Splitting
c. Reducing Procedure Calls
d. Converting to Pointer Code
3. Which of the following is/are related to
optimizing program performance by making it
running fast (b)
I. By using faster algorithm
II. By not using pointer
III .By using data structure that occupy less
memory space
a. II and III only
b. I only
c. I, II, and III
d. I and II only
4. Which of the following is normal skill of making
program run faster (d)
I. Reducing Procedure Calls
II. Enhancing Parallelism
III. Eliminating Unneeded Memory References
a. I, II, and III
b. I and II only
c. II and III only
d. all
5. In order to optimizing program performance, we
should know (a)
I. What is the hot spot
II. Understanding features of that processor on
which the program will run
III. All the system calls that the program uses.
a. I and II only
b. I only
c. II and III only
d. I, II, and III
6. To quickly allocate and free many variables of a
commonly used data type, we could (a)
a. keep a linked list of free objects of that type's
size.

b. minimize the size of the data type.
c. use sizes which are powers of two.
d. coalesce blocks when they are freed.
7. On the following opinions of optimizing C
programs, which is/are right? (a)
I. Just config the compiler in its optimizing setting,
then nothing else need to
II. Understanding the feature of CPU is needless
III. Everything can be done in the C level, so it is
needless to know the assembly code
a. none
b. b. I and II only
c. II and III only
d. I only
8.On profiling, which is/are wrong? (a)
I.GPROF is the profilling tool on Linux platform
II. it can be used to estimate where time is spent in
the program
III. it can incorporate instrumentation code to
determine how much time the different parts of
the program require.
a. none
b. II only
c. III only
d. I only
9. Which of the following approaches towards
advisable? (c)
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.
10. Which of the following is not optimization
technique? (c) <!--[if !ppt]--><!--[endif]-->
a. constant folding
b. code motion
c. memory aliasing
d. loop unrolling
Multiple Choice Quiz 11
1. Which of the following is (are) true of the
concept of locality of reference? (d)
I. It is used to predict future memory references
precisely, with the help of the compiler.
II. It is a quality of typical programs.
III. It has been mathematically proven.
a. II and III only
b. I and II only
c. I only
d. II only
2. Which of the following levels of a typical
memory hierarchy transfers data in chunks of
biggest size? (d)
a. cache <--> main memory.
b. CPU registers <--> cache.
c. they all transfer one byte at a time.
d. main memory <--> disk.
3. Current technology trends suggest that the need
for memory hierarchies (d)
a. will disappear when "broadband"
communications start delivering data over the
internet at speeds greater than 1Mbps.
b. will disappear once processors reach clock
frequencies greater than about 1000MHz.
c. will disappear once DRAM speeds improve.
d. will never disappear.
4. Which of the following is necessarily true
regarding the following code fragment? (b)
a = b;
c = d;
if (e == 1) return;a. It exhibits no locality of reference.b. It exhibits locality of reference no matter wherethe variables are allocated.c. It exhibits locality of reference but only when a== b.

d. It exhibits locality of reference because the
variables are allocated near each other.
5. Which of the following manages the transfer of
data between the cache and main memory? (c)
a. Compiler.
b. Operating System.
c. Hardware.
d. Registry.
6. Which of the following levels of a typical
memory hierarchy transfers data in chunks of
smallest size? (d)
a. they all transfer one byte at a time.
b. main memory <--> disk.
c. cache <--> main memory.
d. CPU registers <--> cache.
7. Compared to dynamic RAM (SRAM), disks are
I. more expensive per megabyte. II. slower per
word access. III. more persistent. (c)
a. I only.
b. I and III only.
c. II and III only.
d. II only.
8. Which of the following manages the transfer of
dat
a
bet
ween
t
he
CP
U
r
and the cache? (d)
a. Hardware.
b. Operating System.
c. Registry.
d. Compiler.
9. A memory hierarchy (b)
a. limits programs' size but allows them to execute
more quickly.
b. takes advantage of the speed of SRAM and the
capacity of disk.
c. makes programs execute more slowly but allows
them to be bigger.
d. is a way of structuring memory allocation
decisions.
10. Compared to static RAM (SRAM), dynamic RAM
(DRAM) is (c)
1. more expensive per megabyte.
2. slower per word access.
3. more persistent.
a. I only.
b. II and III only.
c. II only.
d. I and III only.
Multiple Choice Quiz 12
1.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
parameters 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 executes with a hit ratio of 0.92 on A,
and of 0.97 on B. .
Which of the following statements is valid? (d)
a. The wall time is still the same on A and B, though
it is smaller than 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.
2.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 array a will be fetched into
the cache from main memory?
int a[100];
for (i = 0; i < 17; sum += a[i], i++);
(d)
a. exactly 17.
b. exactly 32.
c. at most 68.
d. at most 96.
3.LRU is an effective cache replacement strategy
primarily because programs(a)
a. exhibit locality of reference
b. usually have small working sets
c. none of the above
d. read data much more frequently than write data
4 . Which facts about the cache can be
determined by calling the following function? .
(a)
int data[1 << 20];
void callee(int x) {
int i, result;
for (i = 0; i < (1 << 20); i += x) {
result += data[i];
}
}
I cache line size
II cache size
III cache speed
a. I only
b. I and III only
c. I and II only
d. I, II, and III
5. Consider the following fragments from two
versions of a program. Version A Version B
// Version A
for (i = 0 ; i < N ; i++ ) {
Read(i);
Calculate(i);
Write(i);
}
// Version B
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?(a)
I B may be faster because of cache effects.
II B may be slower because of cache effects.
III B may execute at essentially the same speed as
A.
a. I, II, and III
b. II and III only
c. I only
d. I and III only
6.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? (b)
a. choosing the cache location currently occupied
by the least-recently-used data.
b. randomly selecting a cache location for the new
line.
c. denying the memory operation that caused the
fetch of the new line.
d. choosing always the same cache location for the
new line.
7.About the cache in a computer system, which is
true(d)
(a) Every computer system has 3 level cache, that is
L1, L2, L3 cache
(b) Every computer systems' cache system have
data cache and instruction cache
(c) Every computer systems' cache system has 2
level cache, that is L1, and L2 cache
(d) Every computer system's cache system has L1
and L2 cache inside CPU chip
a. I only
b. I and III only
c. II and III only
d. none
8.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? (c)
a. Every instruction fetch will cause a cache miss.
b. No bytes will be fetched from main memory

c. There is no telling, from the information given,
how many bytes will be fetched from main
memory.
d. Some bytes, but at most 256 Kbytes, will be
fetched from main memory.
9. 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? (a)
I.B executes a program more quickly than A.
II.A executes a program more quickly than B.
III.While executing a program, A fetches more data
from main memory than does B.
a. I and II only.
b. I, II and III.
c. I and III only.
d. II only.
10.Your computer has 32-bit integers and a direct
cache containing 128 32-byte cache lines. In the
following code fragment, the compiler allocates a
at address 0x800000 and b at address 0x801000.
Before the execution of the code fragment, 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
fetched into the cache from main memory, during
the execution of the code? (d)
int b[1024];
int a[1024];
for (i = 0; i < 17; sum += a[i] + b[i], i++);
a. 68
b. 17
c. 96
d. 1088
Multiple Choice Quiz 13
1.What can Loader do?(c)
I. translate the C code into machine code
II.Resolution
III.load or map the Executable object file from the
disk to memory
a. I and II only.
b. I and III only.
c. III only.
d. I, II and III.
2.What can Linker do?(c)
I. Resolution
II.Relocation
III.Take the same kind of sections from relocatable
object files, and put them together according to
their types
a. II only.
b. I and III only.
c. I, II and III.
d. I and II only.
3.Where the field, which describes whether
Relocatable object file is using little endian or big
endian, locates?(a)
a. ELF header
b. .text
c. .bss
d. Section header tables
4.At what time can linking happen?(a)
I.compile time
II.load time
III.run time
a. I, II and III.
b. II only.
c. I and III only.
d. I and II only.
5.Read the following code in two C files.
//a.c file
extern int shared
int main()
{
int a=100;
swap(&a,&shared);
}
//b.c
int shared=1;
void swap(int *a, int*b)
{
*a ^= *b ^= *a ^= *b
}
After compiling, about the Relocatable Object files,
which is right?(d)
I. in the .symtab of a.obj, swap is UND
II. in the .symtab of b.obj, swap is UND
III. in the .symtab of a.obj, shared is UND
IV. in the .symtab of b.obj, shared is UND
a. IV only.
b. all
c. I and II only.
d. I and III only.
6.Which section is used for resolution(b)
I. ELF header
II. Section header tables

III. .symtab
IV. .rel.text and .rel.data
a. I and II only.
b. III only
c. IV only.
d. I and III only.
7.Which variable will be put into BSS? (b)
int printf( const char* format, ... );
int global_init_var = 84;
int global_uninit_var;
void func1( int i ) {
printf( "%d\n", i);
}
int main(void) {
static int static_var = 85;
static int static_var2;
int a = 1;
int b;
func1( static_var + static_var2 + a + b );
return a;
}
I a and b
II static_var
III global_init_var
IV global_uninit_var;
a. I only
b. IV only
c. II only
d. III only
8.Which section is used for relocation(c)
I. ELF header
II. Section header tables
III. .symtab
IV. .rel.text and .rel.data
a. I and II only.
b. I and III only.
c. IV only.
d. III only
9.From the time when a C program is written, to
the time when it is running as a process on
Windows, what should be done?(a)
I.compile
II.link
III.load.
a. I, II and III.
b. II only.
c. I and II only.
d. I and III only.
10.Which file format is used for Executable object
file(b)
I. PE
II. COFF
III.ELF
IV. a.out
a. II only.
b. all
c. I and II only.
d. I and III only.
Multiple Choice Quiz 14
1.What is right about Exception?(a)
I. To handle it, Hardware and Software cooperation
are needed
II.It is just a Hardware issure
III. It is hardware platform dependent
a. I and III only.
b. I and II only.
c. I, II and III.
d. II only.
2.What is right about Exception Handler?(a)
I.It is used for handle exception
II.It may not return
III.It may return to the instruction where exception
happen
a. I, II and III.
b. I and II only.
c. I and III only.
d. II only.
3. Which function is related to Message Loop (a)
I. Interrupt
II.Trap
III. Fault
IV. Abort
a. II.
b. III.
c. IV
d. I .
4.In IA32 or X86, the Exception includes(a)
I. Interrupt
II.Trap
III. Fault
IV. Abort
a. All.
b. I, II and III.
c. I and II only.
d. I and III only.
5.Which function is related to Message Loop?(a)
I. GetMessage()

II.TranslateMessage()
III.DispatchMessage()
a. I, II and III.
b. I and III only.
c. I and II only.
d. II only.
6.In IA32 or X86, Which Exception is used to
implement Demand Paging(c)
I. Interrupt
II.Trap
III. Fault
IV. Abort
a. I .
b. IV
c. III.
d. II.
7.what is right about Trap?(c)
I.it is a kind of Exception
II.it can be used to implement system call
III.it can be used to implement Hard Disk interrupt
a. I and III only.
b. I, II and III.
c. I and II only.
d. II only.
8.What is right about the Process and Thread of
Windows(a)
I. Process is the unit of Resource ownership
II.Process is the unit of Scheduling/execution
III.Thread is the unit of Scheduling/execution
a. I and III only.
b. I, II and III.
b. I, II and III.
d. I and II only.
9.About process, which one is right?(a)
I. By using process, we are presentded the illusion
that Our program appears to have exclusive use of
both the processor and the memory
II. process is a running program
III. process is possible by the help of Exception
a. I, II and III.
b. I and III only.
c. I only.
d. I and II only.
10.Which is the start point of a Windows
program?(b)
a. Message Loop
b. WinMain function
c. Callback funtion.
d. WndProc function.

posted @ 2022-01-04 21:39  PARADOXS  阅读(783)  评论(0编辑  收藏  举报