Final Flashcards

1
Q

C++ not only supports OOP but also supports other programming styles. T or F

A

T

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

In C++ the variables Alpha, ALPHA and AlphA are the same identifier. T or F

A

F

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

In C++ the compiler will infer the type intended for a variable from the context in which the variable occurs. T or F

A

F

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

A C++ variable declaration includes a name and data type. T or F

A

T

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

A C++ declaration is a definition that also allocates storage for an identifier’s value (or function’s body etc.). T or F

A

T

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

C++ uses only / / for comments. T or F

A

F

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Code, within the same block, after a return or a call to the exit function, will not be executed. T or F

A

T

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
It is legal to replace the prototype
double totalCost(int numberParam, double priceParam);
with the more terse, alternate form
double totalCost(int, double); T or F
A

T

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Extensive use of global variables is a satisfactory replacement for the difficulties of parameter passing with functions. T or F

A

F

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

A variable declared outside any function is said to be a local variable. T or F

A

F

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Consider two blocks, one within another. If an identifier is declared as a variable in the inmost of these two blocks, one can access this variable from the outer block. T or F

A

F

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Given the declaration
int x = 0;
The following expression causes a divide by zero error:
(x == 0) || (2/x < 1); T or F

A

F

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

In a while loop, the boolean expression is executed before each execution of the loop body. T or F

A

T

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

A break statement is used in loops only. T or F

A

F

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

When a loop is nested inside another loop, a break terminates the outermost loop of the nested loop structure. T or F

A

F

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Curly braces are required around a single statement contained in a control structure. T or F

A

F

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

The range of values for an unsigned int variable is from about -4 billion to +4 billion. T or F

A

F

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

In C++, which of the following is a legal identifier?

a) 9xyz
b) @Xyz
c) X+yz
d) xy_z
e) a and d

A

D

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Pick the word that is not a C++ keyword out of the following list.

a) while
b) boolean
c) double
d) if
e) none of the above

A

B

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Which of the following types is not built into the C++ language:

a) bool
b) real
c) short
d) long
e) double

A

B

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

An l-value is

a) an expression that can be only be placed on the left of any operator such as +, * , /, etc.
b) assigned a value
c) can never have a value fetched from it
d) is designed for use by a left-handed person

A

B

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

The value of the expression 20.0 * (9/5) + 32.0 is

a) 68.0
b) 52.0
c) incorrect expression so there is no value
d) 32.0
e) incorrect expression , the / should be %

A

B

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

A call to a C++ function is
a) The name of the function followed by empty parentheses.
b) The name of the function followed by any number of arguments, regardless of the
number of parameters in the definition.
c) The name of the function followed by a number of arguments not greater than the number
of parameters in the definition.
d) The name of the function only.
e) none of the above

A

C

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

A void function
a) performs some action and returns a value
b) performs some action but does not return a value
c) is a statement
d) call is written much like a call to a value returning function but is terminated with a
semicolon.
e) may return a value but is not required to have one.

A

B

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

A definition of a variable outside any function is called a

a) local function definition
b) global variable definition
c) global function header
d) global function definition
e) local variable definition

A

B

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

Where can you not declare a variable in a C++ program?

a) Within the parameter list of a function definition
b) Within the block of a void function.
c) Within the argument list of a function call
d) Within a block nested within another block
e) Within the block of a value returning function.

A

C

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q
Assume this code fragment is embedded in an otherwise correct and complete program. What should be the output from this code segment?
{
for( int i = 0; i < 10; i++)
{
.. .
}
cout << i << endl;
}
a) 10
b) 9
c) 0
d) The variable i is undefined in this scope, so this should not compile
e) none of the above
A

D

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

What is the difference between executing the return 0; statement and its rough equivalent, a call to the exit(0); function, or the difference between return 1; and exit(1);?

a) These are very nearly equivalent anywhere they are encountered.
b) These are very different if encountered in a function other than main();.The exit function terminates the program, returning control to the operating system, whereas return only terminates the function, returning control to the calling function.
c) Both these return control to the free store manager by way of the exception controller, sending the argument as an error code.
d) none of the above

A

B

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

Given the following include directive (to get the declaration for the pow function from the math library):
#include
Now make these declarations:
double base = 2, exponent = 3, power = 4;
Which of the following are syntactically correct invocations for the pow function?
a) power = pow(base, exponent);
b) pow(power, base, exponent);
c) pow(base, exponent) = power;
d) base = pow(exponent, power);
e) both a and d

A

E

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

Which control construct repeats a sequence of statements zero or more times?

a) while statement
b) do-whilestatement
c) switch statement
d) if-elsestatement
e) none of the above

A

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

Which of the following is not true of the || operator?

a) It has two operands.
b) It can have one operand.
c) It is the logical OR operator.
d) It returns true if either operands is true.
e) It uses short circuit evaluation.

A

B

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

In a switch statement, when a break statement is encountered, an immediate transfer of control is made to

a) the default case of the switch statement
b) agotostatement
c) the else clause
d) the statement beyond the end of the switch statement.
e) none of these

A

D

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

In distinguishing an expression as true or false, C++ sees which of the following as true?

a) true
b) Thecharacter’F’
c) 1
d) Anynon-zerovalue
e) all of the above

A

E

34
Q

Which of the following determines the operator that is processed prior to another operator?

a) Operator precedence
b) Whether the operator is an arithmetic operator
c) None of these determine the order in which operators are processed.
d) none of the above
e) all of the above

A

A

35
Q

Which of the following loop statements is guaranteed to iterate the body of the loop at least once?

a) while(control) body;
b) do body while(control);
c) for (initialize; test; update) body;
d) none of the above

A

B

36
Q
If this code fragment were executed in an otherwise correct and complete program, what would the output be?
int a = 3, b = 2, c = 5
if (a > b)
a = 4;
if ( b > c)
a = 5; else
a = 6;
cout << a << endl;
a) 3
b) 4
c) 5
d) 6
e) None of the above, the cout statement belongs to the else and so is skipped.
A

D

37
Q

If the following code fragment is executed in an otherwise complete and correct program, which expression will be executed?
x = 0;
if (x = 12)
yes_statement;
else
no_statement;
a) The no_statement will be executed because x is not 12.
b) The statement has incorrect syntax so will not compile at all.
c) x=12 is illegal in the Boolean expression of an if statement.
d) The yes_statement will be executed.

A

D

38
Q
Given the function, and the main function calling it: What is the output of the following code if you omit the ampersand (&amp;) from the first parameter, but not from the second parameter? (You are to assume this code is embedded in a correct function that calls it.):
#include 
using namespace std;
void func(int &amp; x, int &amp; y)
{
int t = x;
x = y;
y = t;
}
int main() {
int u = 3; v = 4;
// ...
cout << u << " " << v << endl;
func ( u, v );
cout << u << " " << v << endl;
// ...
}
a) 3 4 3 3 
b) 3 4 4 3 
c) 3 4 3 4 
d) 3 4 4 4
e) none of the above.
A

A

39
Q

The statements int x = 1; int y; y = (++x)++;

a) Assign y the value 2;
b) Change the value of x to2.
c) Assign y the value 0;
d) Assign y the value 1;
e) none of the above.

A

A

40
Q

Structure definitions are usually local (defined inside functions). T or F

A

F

41
Q

A structure member is access using the index operator [ ], with the member name as index. [ ] T or F

A

F

42
Q

The following definition of the structure variables of type myStruct s and t could be
made using several definitions using the structure tag.
struct myStruct
{
int i;
double d;
} s, t; T or F

A

T

43
Q
Consider the struct definition below. This will set a's i member variable to 3. struct myStruct
{
int i;
double d; };
...
myStruct a;
a->i = 3; T or F
A

F

44
Q

In C++, accessing an element outside your array bounds can cause a segmentation fault. T or F

A

T

45
Q

It is legal to assign C-string variables, i.e. str1 = str2; T or F

A

F

46
Q

A structure variable can be defined directly in the same statement that defines a structure
definition. T or F

A

T

47
Q

A design technique is to break a problem into smaller tasks, with the prospect that a smaller
problem will be easier to solve. If the smaller task is the identical to the original task excepting only that the size is smaller, the problem may be solved using a recursive algorithm, and implemented with a recursive function. T or F

A

T

48
Q

A proper recursive solution requires at least two cases: a recursive function that calls the recursive function with a smaller problem, and a base, or stopping case. T or F

A

T

49
Q

A recursive function must not return a value. T or F

A

F

50
Q

C-string literals are written ‘Hello’. T or F

A

F

51
Q

A C-string variable is just an array of characters. T or F

A

F

52
Q

It is illegal to write char message[] =”Go Beavers!”; T or F

A

F

53
Q

An array behaves like a list of variables each of which is of the same type and for which
there is a uniform, convenient naming convention that can be declared in a single line of
code. T or F

A

T

54
Q

When using an array, it is perfectly legal to access indexed variables with index values less
than 0 or greater than or equal to the declared size of the array. T or F

A

F

55
Q

In the definition, double d[10] = {1.0};, all the elements in d are initialized to
1.0. T or F

A

F

56
Q

You can assign a C++ standard string to a C-string variable, using the c_str() member function of the C++ string object. T or F

A

T

57
Q

Dynamic variables or dynamically allocated variables in C++ are created and destroyed according to the program’s needs. T or F

A

T

58
Q

Indexed variables for an array are stored wherever the computer finds memory for the first indexed variable, then the next one is stored next to the first if there is space, and someplace else if not. T or F

A

F

59
Q

To call a function with an array parameter, write the array argument as the array name followed by empty square brackets, as in f(a[], 7); T or F

A

F

60
Q

One can use the * operator to extract the value that a pointer points to. T or F

A

T

61
Q

With arrays, indices start at any number the programmer chooses to indicate in the definition. T or F

A

F

62
Q

You can use the size() function to determine the length of a C-string. T or F

A

F

63
Q

To read a character at a time, or to write a character at a time, declare a character variable ch
and write this:
cin&raquo_space; ch; T or F

A

F

64
Q

You can get a pointer value to initialize a pointer variable from an object of an appropriate type with the “address-of” operator, &. T or F

A

T

65
Q

When declaring several pointer variables, there must be one pointer declarator for each pointer variable, i.e. double p1, p2, p3; T or F

A

T

66
Q

Which of the following is a correct statement?
When a function having an array formal parameter is called, void f(int a[]);, the formal array parameter …
a) names a copy of the array argument.
b) refers to exactly the same array as the calling program
c) is passed the address of the argument, and the function needs further information about the
array size to safely use an array parameter
d) refers to the array using a name that is always different from the calling program’s argument.

A

C

67
Q

Which of the following is a valid C-string?

a) ‘\n’
b) ‘n’
c) “Lamb\n”
d) “Mary\0”
e) “M”

A

D

68
Q

Given the array declaration, int a[20]; The second element is written as:

a) a[1]
b) a[0]
c) a
d) a[2]
e) a[3]

A

A

69
Q
How many times is the following code invoked by the call recursive(4)? void recursive( int i )
{
using namespace std;
if (i < 8)
{
cout << i++ << " ";
recursive(i);
}
}
a) 2
b) 4
c) 8
d) 32
e) This is an infinite recursion.
A

B

70
Q

In a recursive solution to a problem, we solve a problem P(n) by solving another problem P(k) where

a) P(k) is the hardest part of P(n)
b) P(k) is a larger problem than P(n)
c) P(k) is smaller or equal to P(n)
d) None of the above

A

C

71
Q

Which of the following is not a rule that ensures a correct recursive function?

a) Each stopping case must perform a correct action (or return the correct value for stopping
case) for the condition that invokes it.
b) The recursion must make no more than 1000 recursive calls.
c) The chain of recursive calls eventually must reach one of the stopping cases.
d) For cases that involve recursion: If each recursive calls correctly solve the subproblem (or return the correct value for the subproblem) it solve, then the final

A

B

72
Q

A recursive function is one that

a) Speeds up a program.
b) Is always slower than a nonrecursive function.
c) Calls itself
d) Calls no functions at all.
e) Calls another function

A

C

73
Q
Consider the function definition and array declarations. Which is the correct call to the function make_1?
void make_1 ( int a[], int size )
{
for (int i = 0; i < size; i++ )
a[i] = 2;
}
int array1[20];
a) make_1( &amp;array1, 30 ); 
b) make_1( array1, 10 ); 
c) make_1( *array1, 50 ); 
d) make_1( array1[],50 );
A

B

74
Q
Given the definition and code fragment:
int matrix[2][3];
int k = 0;
for(int i =0; i < 2; i++)
for (int j=0, j < 3; j++)
matrix[i][j] = k++;
The value of matrix[1][0] is 
a) 0
b) 1
c) 2
d) 3 
e) 4
A

D

75
Q

Some pointer arithmetic is allowed. Which of the following arithmetic operators is not allowed?

a) pointer + integer
b) pointer + pointer
c) pointer - integer
d) integer * pointer
e) both c and d

A

D

76
Q

The header file that you must #include to have access to the Standard Library C-string functions is

a) C-string
b) string.h
c) string
d) String.h
e) None of the above

A

B

77
Q
Given the definitions,
int p1, p2;
p1 = new int;
p2 = new int;
Which is the correct way to make p1 point to the same thing as p2?
a) p1 = p2; 
b) p1 = &amp;p2; 
c) p1 = p2; 
d) *p1 = p2;
A

C

78
Q
Given the structure type and variable definitions
struct ShoeSize
{
char width;
int number;
};
struct ShoeType
{
char style;
ShoeSize size;
double price;
};
ShoeType shoe1;
Which of these is an illegal call to a member variable? 
a) shoe1.style
b) shoe1.width
c) shoe1.size.number
d) shoe1.price
A

B

79
Q
Here is a recursive function. How many times is Hip, printed with the following call,
rec_cheers(5);
void rec_cheers(int n)
{
using namespace std;
if(1==n)
cout << "Hurray!" << endl;
else
{
cout << "Hip, ";
rec_cheers(n-1);
} }
a) 5
b) 4
c) 3
d)2
e) None of the above
A

B

80
Q

Which is the correct way to dynamically create a 1-d array of 6 integers on the heap?

a) int p1[6];
b) int (splat)p1 = new int(splat)[6];
c) int (splat)p1[6];
d) int (splat)p1 = new int[6];

A

D

81
Q

Which of the following does not define a C-string containing “Hello”?

a) char stringVar[10] = “Hello”;
b) char stringVar[10] = {‘H’, ‘e’, ‘l’, ‘l’, ‘o’};
c) char stringVar[10] = {‘H’, ‘e’, ‘l’, ‘l’, ‘o’, ‘\0’};
d) char stringVar[6] = “Hello”;
e) char stringVar[] = “Hello”;

A

B