Shared Flashcard Set

Details

2nd half class for cumulative final
The quiz questions and answers to my quizes for Ch 6- 8
105
Computer Science
Undergraduate 3
07/22/2013

Additional Computer Science Flashcards

 


 

Cards

Term
The function prototype

    double mySqrt( int x );
Definition
Declares a function called mySqrt which takes an integer as an argument and returns a double
Term
An identifier’s storage class:
Definition
Determines the period during which that identifier exists in memory
Term
Labels are the only identifiers with:
Definition
Function scope
Term
Which of the following C++ Standard Library headers does not contain a C++ Standard Library container class?
Definition
< string >
Term
The rand function generates a data value of the type:
Definition

unsigned int

 
Term
A function prototype does not have to:
Definition
Include parameter names
Term

Which of the following is false about the following function prototype? void functionA( void );

 
Definition
It could have been written functionA( void )
Term
A recursive function is a function that
Definition
Calls itself, directly or indirectly
Term
Given the following function template 
 
template < class T > 
T maximum( T value1, T value2 ) 
     if ( value1 > value2 ) 
          return value1; 
     else 
          return value2; 
 
what would be returned by the following two function calls? 
 
maximum( 2, 5 ); 
maximum( 2.3, 5.2 );
 
Definition
5 and 5.2
Term
Recursion is to the base case as iteration is to what:
Definition
Failure of the loop continuation test
Term
In order to calculate the __________ of an array of values, the array values must be summed.
Definition
Average
Term
Constant variables:
Definition
Can be used to specify array sizes, thereby making programs more scalable
Term
Unless otherwise specified, entire arrays are passed __________ and individual array elements are passed __________.
Definition

 By reference, by value

Term
Which of the following is false?
Definition
A subscript cannot be an expression
Term

Given the following declaration, what is the value of b[ 1 ][ 0 ]?

 

     int b[ 2 ][ 2 ] = { { 1 }, { 3 , 4 } };

Definition
3
Term
Which of the following is false about a function to which an array is being passed?
Definition
It always knows the size of the array that is being passed
Term
Which statement about exception handling is false?
Definition
Bounds checking is performed at execution time with vector member function at, and if a subscript is within the bounds of the array, the member function throws an out_of_bounds exception
Term
Using square brackets ([]) to retrieve vector elements __________ perform bounds checking; using member function at to retrieve vector elements __________ perform bounds checking
Definition
Does not, Does
Term
An array is not:
Definition
Made up of different data types
Term
To prevent modification of array values passed to a function:
Definition
The array parameter can be preceded by the const qualifier
Term

( *max )( num1, num2, num3 );

 
Definition
Is a call to the function pointed to by max
Term
Assuming that t is an array and tPtr is a pointer to that array, which expression refers to the address of element 3 of the array?
Definition
&t [ 3 ]
Term
sizeof:
Definition
Returns the total number of bytes in a variable
Term
Pointers cannot be used to:
Definition
Reference values directly
Term
Which of the following gives the number of elements in the array int r[ 10 ]?
Definition
sizeof r / sizeof ( int )
Term
The & operator can be applied to:
Definition
lvalues
Term
Which of the following can have a pointer as an operand?
Definition
++
Term

Consider the following function:

 

void reverse( char *string1, const char *string2 )

{

   int stringsize = sizeof( string1 )/sizeof( char );

   *( string1 + stringsize –1 ) = '\0';

   string1 = string1 + stringsize – 2;

   for ( ; *string2 != '\0'; string1--, string2++ )

      *string1 = *string2;

}

What method does the function use to refer to array elements?

Definition
Pointer/offset notation
Term
Three of the following expressions have the same value. Which of the following expressions has a value different from the others’?
Definition
*ptr
Term
Given that k is an integer array starting at location 2000, kPtr is a pointer to k and each integer is stored in 4 bytes of memory, what location does kPtr + 3 point to?
Definition
2012
Term
All of the following are true of functions except:
Definition
The definition of a function usually is visible to other functions.
Term
Functions can:
Definition
Do any of the above.
Term
All math library functions:
Definition
Are global functions.
Term

Which of the following expressions returns the trigonometric sine of x?

 
Definition
sin( x ).
Term
Which of the following is not included in ?
Definition

log. 

 

ln.

 
Term

 Using the following function definition, the parameter list is represented by:

A B ( C )

{

   D

}

Definition
C.
Term

A function prototype does not have to: 

 
Definition
Include parameter names.
Term

A function prototype can always be omitted when:

 
Definition
A function is defined before it is first invoked.
Term
Converting from type ________ to type ________ will result in the loss of data.
Definition
int, char
Term
Each standard library has a corresponding:
Definition
Header file
Term

Which of the following C++ Standard Library header files does not contain a C++ Standard Library container class?

 
Definition
<string>
Term

 The rand function generates a data value of the type: 

 
Definition
unsigned int
Term
A variable that can only have values in the range 0 to 65535 is a:
Definition
Two-byte unsigned int
Term
In the expression n = x + rand() % y;
Definition
y is the scaling value
Term
srand:
Definition
Can use the time function’s return value as an optimal seed value.
Term
Enumeration constants:
Definition

Must have unique identifiers.

 
Term

Depending on the circumstances, the compiler may ignore the storage class specifier:

 
Definition
register.
Term

 Which of the following is not true of static local variables?

 
Definition
They are accessible outside of the function in which they are defined.
Term

 Labels are the only identifiers with: 

 
Definition
Function scope.
Term

 The only identifiers that can be reused elsewhere in a program without any ambiguity are:

 
Definition
Those in the parameter list of a function prototype.
Term
An activation record will be popped off the function call stack whenever:
Definition

A function returns control to its caller.

 
Term
Which of the following is not included in a function’s activation record?
Definition
The name of the function.
Term
The inline keyword:
Definition
Can reduce a function’s execution time but increase program size.
Term
A reference parameter:
Definition

Both (a) and (b).

 
Term
Call-by-reference can achieve the security of call-by-value when:
Definition

The const qualifier is used.

 
Term
In regards to default arguments, which of the following is false?
Definition
Default values cannot be global variables or function calls
Term
If the function int volume( int x = 1, int y = 1, int z = 1 ); is called by the expression volume( 3 ), how many default arguments are used?
Definition
Two.
Term
The unary scope resolution operator is used:
Definition
To access a global variable when a local variable of the same name is in scope.
Term

Which of the following does the C++ compiler not examine in order to select the proper overloaded function to call? 

 
Definition

The return type of the function.

 
Term
If a function’s program logic and operations are identical for each data type it could receive as argument(s) then a __________ should be used.
Definition
Function template.
Term

 Assuming the following pseudocode for the Fibonacci series, what is the value of the 5th Fibonacci number (fibonacci ( 5 ))? 

 

     fibonacci( 0 ) = 0

     fibonacci( 1 ) = 1

     fibonacci( n ) = fibonacci( n – 1 ) + fibonacci( n – 2 )

 
Definition
5.
Term
Assuming that int a has a value of 3 and that integer array b has 7 elements, what is the correct way to assign the value of the third element plus 3, to the fifth element of the array:
Definition
b[ a + 1 ] = b[ a - 1 ] + 3;
Term
Which statement would be used to declare a 10-element integer array c?
Definition
int c[ 10 ];
Term
Which of the following is not a correct way to initialize an array?
Definition
int n[ 5 ] = { 0, 7, 0, 3, 8, 2 };
Term

 Constant variables:

 
Definition
Can be used to specify array sizes, thereby making programs more scalable.
Term
Referencing elements outside the array bounds:
Definition
Can result in changes to the value of an unrelated variable.
Term
Strings represented as character arrays cannot:
Definition
Grow or shrink dynamically.
Term

Which of the following character array declarations does not produce a string? 

 
Definition
char string1[] = { ‘t’, ‘e’, ‘s’, ‘t’ };.
Term
Linear search can be used on:
Definition
Any of the above.
Term
Linear search is highly inefficient compared to binary search when dealing with:
Definition
Large, sorted arrays
Term

 Which statement about insertion sort is true? 

 
Definition

The algorithm is very simple compared to other sorting procedures.

 
Term

At the ith iteration of the insertion sort:

 
Definition
The first i elements of the array are sorted.
Term

 A double subscripted array element declared as a[ 3 ][ 5 ] has how many elements? 

 
Definition
15.
Term
Given the following declaration, what is the value of b[ 1 ][ 0 ]?
Definition
int b[ 2 ][ 2 ] = { { 1 }, { 3 , 4 } };
Term
Which of the following does not declare a 2-by-2 array and set all four of its elements to 0?
Definition

All of the above initialize all of their elements to 0.

 
Term
In a typical nested for loop structure used to process a two-dimensional array, following the end of the each execution of the inner for loop:
Definition

The outer for loop increments its counter variable.

 
Term
Which of the following is not true of class template vector?
Definition
A vector can only store data type int.
Term
In a UML communication diagram, the first message passed during the processing of message 1 is called:
Definition
Message 1.1.
Term

A message between two objects in a UML sequence diagram is represented by:

 
Definition
A solid line with a filled arrowhead.
Term
An activation, represented by a thin vertical rectangle, on an object’s lifeline indicates that:
Definition
The object is executing.
Term
Pointers may be assigned to which of the following?
Definition
Both (b) and (c).
Term

 What does the following declaration declare? 

 

int *countPtr, count; 

Definition
Two pointers to ints
Term

 All of the following could cause a fatal execution-time error except:

 
Definition
Dereferencing a variable that is not a pointer.
Term

 Which of the following is not a valid way to pass arguments to a function in C++? 

 
Definition
By value with pointer arguments.
Term
When a compiler encounters a function parameter for a single-subscripted array of the form int a[], it converts the parameter to:
Definition
int * a
Term
A function that modifies an array by using pointer arithmetic such as ++ptr to process every value should have a parameter that is:
Definition
A nonconstant pointer to nonconstant data.
Term
A function that prints a string by using pointer arithmetic such as ++ptr to output each character should have a parameter that is:
Definition
A nonconstant pointer to constant data.
Term

An array name is:

 
Definition
A constant pointer to nonconstant data.
Term
What method should be used to pass an array to a function that does not modify the array and only looks at it using array subscript notation:
Definition
constant pointer to constant data.
Term
After the ith iteration of the selection sort:
Definition

The smallest i items of the array will be sorted into increasing order in the first i elements of the array.

 
Term
To follow the principle of least privilege, the selectionSort function should receive the array to be sorted as:
Definition
A constant pointer to nonconstant data.
Term
A pointer can not be assigned to:
Definition
A pointer of a type other than its own type and void without using the cast operator.
Term

Comparing pointers and performing pointer arithmetic on them is meaningless unless:

 
Definition
They point to elements of the same array.
Term
Assuming that t is an array and tPtr is a pointer to that array, which expression refers to the address of the fourth element?
Definition
&t[ 3 ]
Term

void reverse( char * string1, const char * string2 )

{

   int stringsize = sizeof( string1 )/sizeof( char );

   *( string1 + stringsize –1 ) = '\0';

   string1 = string1 + stringsize – 2;

   for ( ; *string2 != '\0'; string1--, string2++ )

      *string1 = *string2;

}

 

What method does the function use to refer to array elements?

 
Definition

Pointer/offset notation.

 
Term
A string array:
Definition
Is actually an array of pointers.
Term

A string array is commonly used for:

 
Definition
Command-line arguments
Term
An algorithm that could execute for an unknown amount of time because it depends on random numbers may:
Definition
Suffer from indefinite postponement
Term
Which of the following is not true of pointers to functions?
Definition

They can not be assigned to other function pointers.

 
Term
Which of the following is not true?
Definition

String literals are written inside of single quotes.

 
Term

cin.getline( superstring, 30 ); is equivalent to which of the following? 

 
Definition
cin.getline( superstring, 30, '\n' );
Term
Which of the following correctly copies the contents of string2 into string1? Assume that string2 is equal to "goodbye" and string1 is equal to "good morning"?
Definition
strcpy( string1, string2 );
Term
Assuming that string1 = "hello" and string2 = "hello world", which of the following returns 0?
Definition
Strncmp( string1, string2, 5 );
Supporting users have an ad free experience!