CMPSC 121 Exam 2 Study Guide

¡Supera tus tareas y exámenes ahora con Quizwiz!

This operator represents the logical AND:

&&

What will the following code display? int numbers[] = { 99, 87, 66, 55, 101 }; for (int i = 1; i < 4; i++) cout << numbers[i] << " ";

87 66 55

Each function parameter passed by reference must contain #

False

Global variables are initialized by default.

False

In the following statements, no short circuit will occur int x = 12, y = 5, z = -4; z > x && y < x && y == 5

False

Select all that apply. The motivation for modular programming include:

Re-usability of code Simplifies the process of writing programs Improves maintainability of programs

An expression that has any value other than 0 is considered true by an if statement.

True

The value of the result in the following expression will be 0 if x has the value of 12. result = x > 100 ? 0 : 1;

True

Subscript numbering in C++ array

begins with zero

Which of the following statements deletes memory that has been dynamically allocated for an array?

delete [] array;

The contents of pointer variables may be changed with mathematical statements that perform

subtraction ( - ), addition ( + )

When you work with a dereferenced pointer, you are actually working with

the actual value of the variable whose address is stored in the pointer variable

Dynamic memory allocation occurs

when a new variable is created at runtime

Given the following function: void sum(int a, int& b, int c) { int d; d = a + c; b = d * 4; a = a + d; c = c + a; } What is the output of the following code segment that invokes calc(): int x = 1; int y = 2; int z = 1; calc(x, y, z); cout << x << " " << y << " " << z << endl;

1 8 1

What is the output of the following code segment? int x = 8; if (x != 2) { cout << "This is true!" << endl; cout << "That's all, folks!" << endl; } else cout << "This is false!" << endl; cout << "So long, folks!" << endl;

This is true! That's all folks So long, folks!

The amount of memory used by an array depends on the array's data type and the number of elements in the array.

True

Which of the following can be used as pointers?

array names

An array's size declarator must be a __________ with a value greater than __________.

constant integer expression, zero

Use the delete operator only on pointers that were

created with the new operator

To use the exit() function, which of the following header must be included?

cstdlib

After the following code executes, what is the output if the user enters 0? int x = -1; cout << "Enter a 0 or 1: "; cin >> x; if (c) cout << "true" << endl; else cout << "false" << endl;

false

Which of the following is a valid C++ array definition?

int sizes[10];

This type of variable is defined inside a function and is not accessible outside the function.

local

To pass an array as an argument to a function, pass the __________ of the array.

name

This vector function is used to insert an item into a vector.

push_back

When the less than operator (<) is used between two pointer values, the expression is testing whether

the address of the first variable comes before the address of the second variable in the computer's memory

What will the following statement output? cout << &num1;

the memory address of the variable named num1

The range-based for loop in C++11 is designed to work with a built-in variable known as

the range variable

Assuming ptr is a pointer variable, what will the following statement output? cout << *ptr;

the value stored in the variable whose address is contained in ptr

Which statement correctly uses C++11 to initialize a vector of ints named n with the values 10 and 20?

vector<int> n {10, 20};

Which of the following expressions will determine whether x is greater than or equal to y?

x >= y


Conjuntos de estudio relacionados

google interview university (jwasham) 2

View Set

Introduction to the Philippine Folk Dance/ Common Dance Terms in Folkdance

View Set

Global Competition for Products and Services and Jobs

View Set

Information Security Chapter 8 Review Questions

View Set