Programming Fundamentals 1: Exam 3 (Ch 7, 9, 10)

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

The ________ and ________ operators can be used to increment or decrement a pointer variable. -All of these -None of these -++, -- -addition, subtraction -modulus, division

++, --

Select all that apply. Whitespace encompasses which of the following? -a space -a tab -None of these -a newline

-a space -a tab -a newline

Select all that apply. Of the following, which statements have the same meaning? -int ptr = nullptr; -int *ptr = nullptr; -int* ptr = nullptr; -*int ptr = nullptr; -int ptr* = nullptr;

-int *ptr = nullptr; -int* ptr = nullptr;

Select all that apply. Select as many of the following options that make this sentence TRUE: The contents of pointer variables may be changed with mathematical statements that perform -modulus -division -multiplication -subtraction -addition

-subtraction -addition

What will the following code display? int numbers[] = {99, 87, 66, 55, 101}; cout << numbers[3] << endl; -87 -101 -66 -55

55

What does the following code display? int values[] = {2, 6, 10, 14}; cout << values[1]++;

6

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

87 66 55

What does the following code do? string town = "Charleston"; x = town.length(); -Assigns the value 10 to the variable x -Copies the string "Charleston" to the variable x -None of these

Assigns the value 10 to the variable x

A test using the isupper function will return false if the argument is an uppercase character. -True/False

False

Although C++ provides ample library functions to handle numeric values, we must write all of our own functions to manipulate character values. -True/False

False

Although two-dimensional arrays are a novel idea, there is no known way to pass one to a function. -True/False

False

An array initialization must be all on one line. -True/False

False

Assume array1 and array2 are the names of two arrays. To assign the contents of array2 to array1, you would use the following statement: array1 = array2; -True/False

False

C++ limits the number of array dimensions to two. -True/False

False

In C++11 the range-based for loop is best used in situations where you need the element subscript for some purpose. -True/False

False

The C++ compiler performs strict array bounds checking when it encounters an array of characters. -True/False

False

The ampersand (&) is used to dereference a pointer variable in C++. -True/False

False

The following statement is a valid C++ definition: double money[25.00]; -True/False

False

The following string that uses a semicolon as a delimiter contains four tokens: "apple;cherry;lemon cream" -True/False

False

The ftoa function converts a floating-point value to an ASCII value. -True/False

False

The strlen function returns a C-string's length and adds one for \0. -True/False

False

The weak_ptr can share ownership of a piece of dynamically allocated memory. -True/False

False

With pointer variables you can access but not modify data in other variables. -True/False

False

What is wrong with the following code? void doubleVal(int val) { *val *= 2; }

The * operator is used on the parameter, but it is not a pointer

What is wrong with the following code? int x, *ptr = null ptr; *ptr = &x;

The assignment statement should read ptr = &x;

What is wrong with the following code? int *getNum() { int wholeNum; cout << "Enter a number: "; cin >> wholeNum; return &wholeNum; }

The function returns the address of a variable that no longer exists

What is wrong with the following code? void doSomething(int *const ptr) { int localArray[] = {1, 2, 3}; ptr = localArray; }

The function tries to change the contents of ptr, which is a constant pointer. During the functions execution, the value in ptr cannot be changed

What is wrong with the following code? int numbers[] = {10, 20, 30, 40, 50}; cout << "The third element in the array is "; cout << *numbers + 3 << endl;

The last line should read cout << *(numbers + 3) << endl;

What is wrong with the following code? int *pint = nullptr; pint = new int; if (pint == nullptr) *pint = 100; else cout << "Memory allocation error\n";

The program segment is storing a value at the address 0

A vector object automatically expands in size to accommodate the items stored in it. -True/False

True

Access of an individual element of an array through an index is done by pointer arithmetic: address + 1 means to move one array element forward from the starting address of the array. -True/False

True

Although variables can be passed by value or reference, arrays are always passed by pointer, which is similar to pass by reference, since it is not efficient to make a "copy" of all elements of the array. -True/False

True

An array name is a pointer constant because the address stored in it cannot be changed at runtime. -True/False

True

An individual array element can be processed like any other type of C++ variable. -True/False

True

Any nonletter argument passed to toupper or tolower is returned unchanged. -True/False

True

Assigning nullptr to a pointer variable makes the variable point to the address 0. -True/False

True

The word consumed means that a character is not read by a function. -True/False

True

To read from a file or from the keyboard, we prime the read, which means the first value is read in before the test condition is checked to see if the loop should be executed. -True/False

True

To use any of the smart pointers in C++11 you must use the following directive in the header file: #include <memory> -True/False

True

To use the C++ case-conversion functions toupper and tolower, you must #include the <cctype> header file. -True/False

True

To use the C++ character-testing functions such as isalpha, isdigit, islower, isprint, and isspace, you must #include the <cctype> header file. -True/False

True

When a reference variable is used, the memory address of the parameter is sent to the function instead of the value at that address. -True/False

True

When a string constant is passed to the cout object, it is the memory address that is actually accessed. -True/False

True

When arrays are passed to functions, they are passed by pointer, and an array name is a pointer to the beginning of the array. -True/False

True

A pointer variable may be initialized with -any nonzero integer value -a valid address in the computer's memory -an address less than zero -any nonzero number -None of these

a valid address in the computer's memory

The following statement ________.int *ptr = new int; -assigns an address to the variable ptr -assigns an integer less than 32767 to the variable ptr -None of these -results in a compiler error -creates a new pointer named int

assigns an address to the variable ptr

The function that converts a C-string to an integer and returns the integer value is -strtoint -atoint -strint -atoi -None of these

atoi

The function that accepts a C-string as an argument and converts the string to a long integer is -strlong -strtolong -None of these -atol -stringlong

atol

Subscript numbering in C++ -can be set at runtime -begins with zero -None of these -varies from program to program -can begin with a value defined by the programmer

begins with zero

Which of the following statements deletes memory that has been dynamically allocated for an array? -delete [] array; -None of these -new array = delete; -int delete[ ]; -int array = delete memory;

delete [] array;

Arrays must be ________ at the time they are ________. -re-scoped, deleted -sized, executed -initialized, declared -compiled, typed -None of these

initialized, declared

Array initialization and processing is usually done inside a _________

loop

What is the output of the following statement? cout << tolower(toupper('Z')) << endl; -a lowercase z followed by an uppercase Z -None of these -lowercase z -uppercase Z -a compiler error

lowercase z

The name of an array stores the ________ of the first array element. -memory address -None of these -data type -value -element number

memory address

In the following statement, what does int mean? int *ptr = nullptr; -The variable named *ptr will store an asterisk and an integer value -None of these -The variable named *ptr will store the value in nullptr. -The variable named *ptr will store an integer value. -ptr is a pointer variable and will store the address of an integer variable.

ptr is a pointer variable and will store the address of an integer variable

This vector function returns the number of elements in a vector. -length -elements -num_elements -size

size

To access an array element, use the array name and the element's ________. -data type -subscript -value -name -None of these

subscript

This vector function removes an item from a vector. -pop_back -delete_item -erase -remove_item

pop_back

What does the following code display? int values[] = {2, 6, 10, 14}; x = 2; cout << values[++x];

14

Select all that apply. Which of the following would be appropriate in a program that allows the user to enter either an uppercase or lowercase character in response to a prompt? -ignoreupper -ignorelower -ignorecase -tolower -touppe

-tolower -toupper

The null terminator stands for ASCII code -0 -57 -100 -1000 -None of these

0

What will the following code display? int numbers[4] = {99, 87}; cout << numbers[3] << endl; -This code will not compile -87 -0 -99 -garbage

0

What is the value stored in num after the following statement executes? num = atoi("1000"); -1000 -None of these -999 -"1000" -"1 thousand"

1000

What will the following code output? int *numbers = new int[5]; for (int i = 0; i <= 4; i++) *(numbers + i) = i; cout << numbers[2] << endl; -2 -3 -five memory addresses -1 -0

2

What will the following code output? int number = 22; int *var = &number; cout << *var << endl; -the address of number -an asterisk followed by the address of number -22 -an asterisk followed by 22

22

In cin.getline(name, 25), the 25 indicates that the user can input at most ____ characters into name. -24 -25 -26 -None of these

24

What does the following code display? int values[] = {2, 6, 10, 14}; cout << ++values[0];

3

What will the following C++11 code display? vector<int> numbers {3, 5}; for (int val : numbers) cout << val << endl; -5 5 5 -3 3 3 3 3 -Nothing. This code has an error. -3 5

3 5

What is the last legal subscript that can be used with the following array? int values[5]; -6 -1 -4 -5 -0

4

Given the string shown below, if the delimiter is a space, how many tokens are in the string? "Tony's email address is [email protected]" -6 -9 -7 -4 -5

5

What header file must you #include in order to define vector objects?

<vector>

A two-dimensional array of characters can contain -uninitialized elements -None of these -strings of the same length -strings of different lengths -All of these

All of these

Which of the following statements is NOT valid C++ code? -float num1 = &ptr2; -int ptr = &num1; -int ptr = int *num1; -All of these are valid -All of these are invalid

All of these are invalid

What does the following code do? const int SIZE = 5; double x[SIZE]; for (int i = 2; i <= SIZE; i++) { x[i] = 0.0; } -Each element in the array is initialized to 0.0. -Each element in the array except the first is initialized to 0.0. -Each element in the array except the first and last is initialized to 0.0. -An error will occur when the code runs.

An error will occur when the code runs.

What is wrong with following code? float level; int fptr = &level;

An int pointer is being used to reference a float value

What does the following statement do? double *num2; -Declares a double variable named num2 -None of these -Declares a pointer variable named num2 -Declares and initializes a pointer variable named num2 -Initializes a pointer variable named num2

Declares a pointer variable named num2

What does the following statement do? vector<int> v(10, 2); -It creates a vector object with a starting size of 2 and initializes the first element with the value 10. -You Answered It creates a vector object with a starting size of 10 and initializes the first element with the value 2. -It creates a vector object and initializes the first two elements with the values 10 and 2. -It creates a vector object with a starting size of 10 and initializes all the elements with the value 2.

It creates a vector object with a starting size of 10 and initializes all the elements with the value 2.

What does the following statement do? vector<int> v(10); -It creates a vector object and initializes all its elements to the value 10. -It creates a vector object with a starting size of 10. -It creates a vector object and initializes the first element with the value 10. -It creates a vector object that can only store values of 10 or less.

It creates a vector object with a starting size of 10.

What is wrong with the following code? int values[20], *iptr = nullptr; iptr = values; iptr *= 2;

Multiplication cannot be performed on pointers

The function that reverses the order of a C-string is -reverseit -reversstr -None of these -strrev -back

None of these

When you pass a pointer as an argument to a function, you must not dereference the pointer in the function's body -dereference the pointer value in the function prototype -declare the pointer value again in the function call -use the #include statement -None of these

None of these

What is wrong with the following code? int ptr* = nullptr;

The variable should be declared as int *ptr;

Which of the following is TRUE about this statement? sum += *array++; -This statement will cause a compiler error. -This statement is illegal in C++. -This statement assigns the dereferenced pointer's value, then increments the pointer's address. -None of these -This statement increments the dereferenced pointer's value by one, then assign that value.

This statement assigns the dereferenced pointer's value, then increments the pointer's address.

A pointer can be used as a function argument, giving the function access to the original argument. -True/False

True

Assuming myValues is an array of int values and index is an int variable, both of the following statements do the same thing. 1. cout << myValues[index] << endl; 2. cout << *(myValues + index) << endl; -True/False

True

Both the getline and get functions do not skip leading whitespace characters. -True/False

True

By being able to pass arrays as arguments, you can write your own functions for processing C-strings. -True/False

True

C++ does not perform array bounds checking, making it possible for you to assign a pointer the address of an element out of the boundaries of an array. -True/False

True

C++11 introduces a function named to_string that converts a numeric value to a string object. -True/False

True

Dereference means that the location of a reference variable is accessed to retrieve or store a value. When * is placed in front of an already defined pointer variable, the data stored a the location the pointer points to will be used and not the address. -True/False

True

Each individual element of an array can be accessed by the array name and the element subscript. -True/False

True

If an array is partially initialized, the uninitialized elements will be set to zero. -True/False

True

If an uppercase character is passed as an argument to the toupper function, the result will be an uppercase character. -True/False

True

In C++11 you can use smart pointers to dynamically allocate memory and not worry about deleting the memory when you are finished using it. -True/False

True

In C++11 you cannot use a range-based for loop to modify the contents of an array unless you declare the range variable as a reference variable. -True/False

True

In C++11, the nullptr keyword was introduced to represent the address 0. -True/False

True

In cin.get(strName, numChar + 1), strName is a string variable and the integer expression numChar + 1 gives the number of characters that may be read into strName. -True/False

True

Inserting the word const before the data type on the formal parameter list prevents a function from altering an array even though it is passed by pointer. -True/False

True

It is legal to subtract a pointer variable from another pointer variable. -True/False

True

Pointers allow us to use dynamic variables, which can be created and destroyed as needed within a program. -True/False

True

Priming the read for a while loop means having an input just before the loop condition (just before the while) and having another one as the last statement in the loop. -True/False

True

The * symbol is basically used on 2 occasions: 1) Used to define pointer variables: int *ptr = nullptr; 2) Used whenever we are interested in the contents of the memory location pointed to by a pointer variable, rather than the address itself. When used this way, * is called the indirection operator or dereferencing operator: cout << *ptr; // The value stored in the address pointed to will be // printed -True/False

True

The C++ 11 function to_string, that converts a numeric value to a string object, requires the <string> header file to be included. -True/False

True

The C++ 11 functions stoi, stol, stoul, stoll, stoull, stof, stod, and stold convert string objects to numeric values and require the <string> header file. -True/False

True

The C++ library function strlen() accepts a pointer to a C-string as its argument and returns the length of the string, which is the number of characters up to, but not including, the null terminator. -True/False

True

The C++ library functions atoi, atol, and atof convert C-string representations of numbers into numberic values and require the <cstdlib> header file. -True/False

True

The C++ library functions strlen, strcat, strcpy, strncat, strncpy, strcmp, and strstr accept C-strings as arguments and require the <cstring> header file. -True/False

True

The C++ library provides functions for converting a string representation of a number to a numeric data type and vice-versa. -True/False

True

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

True

The call cin.ignore(80, '\n'); says to skip over the next 80 input characters but stop if a newline character is read. -True/False

True

The data type returned by isalpha is a bool. Therefore, the value returned by isalpha('g') is a non-zero value (true). -True/False

True

The following 2 statements are equivalent: 1) cout << grades[2]; 2) cout << *(grades + 2); -True/False

True

The following are 2 ways to define a string object named name, initialized with "William Smith": string name("William Smith"); string name = "William Smith"; -True/False

True

The following are the values returned by the strcmp if string1 is the first argument passed and string2 is the second argument passed: 1) The result is zero if the 2 strings are equal on a character-by-character basis 2) The result is negative if string1 comes before string2 in alphabetical order 3) The result is positive if string1 comes after string2 in alphabetical order -True/False

True

The following defines a string object named firstName, initialized with a substring of the string fullName, and the substring is 7 characters long, beginning at position 0: string firstName(fullName, 0, 7); -True/False

True

The following defines a string object named lineFull initialized with 10 'z' characters: string lineFull('z', 10); -True/False

True

The following defines a string object named person1, which is a copy of person2. person2 may be either a string object or a character array: string person1(person2); -True/False

True

The following defines a string object named str1, which is initialized with the first 5 characters in the character array str2: string str1(str2, 5); -True/False

True

The function strcmp takes 2 C-strings as arguments and returns an integer that indicates how the 2 strings compare to each other. -True/False

True

The get function reads in the next character in the input stream, including whitespace. The syntax is cin.get(ch); where ch is a character variable. -True/False

True

The get function, like the getline function, can also be used to read strings, in which case we would need 2 parameters: cin.get(strName, numChar + 1); -True/False

True

The itoa function is similar to atoi but it works in reverse. -True/False

True

The lifetime of a variable is the time during which a variable exists. -True/False

True

The name of an array, without any brackets, acts as a pointer to the starting address of the array. -True/False

True

The operator + returns a string that is the concatenation of the 2 string operands. -True/False

True

The operator += appends a copy of the string on the right to the string object on the left. -True/False

True

The size function member function, like the length member function, can return the length of a string. -True/False

True

The string class is an abstract data type which means it is not a built-in, primitive data type like int or char. You must #include the <string> header file when working with the string class. -True/False

True

The string class's front and back member functions were introduced in C++11. -True/False

True

The typedef statement can be used to declare an array type and is often used for multidimensional array declarations so that when passing arrays as parameters, brackets do not have to be used. -True/False

True

The use of brackets in function prototypes and headings can be avoided by declaring a programmer defined data type. This is done in the global section with a typedef statement: typedef int GradeType[50]; -True/False

True

When reading a line of input into a string object, the getline() function's first argument is the name of the stream object from which you wish to read input, and the second argument is the name of a string object such as getline(cin, name); -True/False

True

When string constants such as "Hello World" are stored in the computer's memory, the null character is automatically appended to the end of the string. -True/False

True

When using the strcat function you must be careful not to overwrite the bounds of an array. True/False

True

When you pass an array as an argument to a function, the function can modify the contents of the array. -True/False

True

You may use the <, >, <=, >=, ==, and != relational operators to compare string objects. -True/False

True

cin >> strName; skips leading whitespace but stops at the first trailing whitespace (which is not consumed). -True/False

True

length is a string class member function that returns the length of the string stored in the object as an unsigned integer. -True/False

True

typedef int GradeType[50]; declares a data type, called GradeType, that is an array containing 50 integer memory locations. Since GradeType is a data type, it can be used in defining variables. The following defines grades as an integer array with 50 elements: GradeType grades; -True/False

True

The escape sequence that represents the null terminator is -None of these -\t -\n -nullptr -\0

\0

To assign the contents of one array to another, you must use -the assignment operator with the array names -the equality operator with the array names -a loop to assign the elements of one array to the other array -Any of these -None of these

a loop to assign the elements of one array to the other array

A pointer variable is designed to store _____________ -any legal C++ value -a memory address -an integer -None of these -only floating-point values

a memory address

Every byte in the computer's memory is assigned a unique -name -pointer -dynamic allocation -None of these -address

address

When writing functions that accept multi-dimensional arrays as arguments, ________ must be explicitly stated in the parameter list. -None of these -all dimensions -the size declarator of the first dimension -all element values -all but the first dimension

all but the first dimension

The ________, also known as the address operator, returns the memory address of a variable. -None of these -percent sign ( % ) -ampersand ( & ) -exclamation point ( ! ) -asterisk (* )

ampersand ( & )

Which of the following can be used as pointers? -array names -numeric constants -keywords -None of these

array names

Unlike regular variables, ________ can hold multiple values. -constants -named constants -arrays -floats -None of these

arrays

The expression being tested by the statement shown below will evaluate to true if var1 is ________. if (!isdigit(var1)) -9 -both an alphabetic character and a symbol such as $ or & -an alphabetic character -None of these -a symbol such as $ or &

both an alphabetic character and a symbol such as $ or &

Which of the following statements appropriately defines a C-string that stores names of up to 25 characters? -string name[24]; -None of these -char name[25]; -string name[25]; -char name[26];

char name[26];

Which of the following defines an array of C-strings that will hold 49 characters and the null terminator? -char[50] str; -character str[50]; -char [49]; -char str[50]; -None of these

char str[50];

An array's size declarator must be a ________ with a value greater than ________. -number, one -number, zero -constant integer expression, zero -variable, -1 -None of these

constant integer expression, zero

Which of the following statements displays the address of the variable numb? -cout << *numb; -cout << numb; -cout << &numb; -cin >> &numb; -None of these

cout << &numb;

Use the delete operator only on pointers that were -created with the new operator -dereferenced inappropriately -never used -not correctly initialized -None of these

created with the new operator

The C-string company[12] can hold -twelve characters -eleven characters and the null terminator -None of these -twelve characters and the null terminator -thirteen characters

eleven characters and the null terminator

This vector function returns true if the vector has no elements. -has_no_elements -null_size -empty -is_empty

empty

An array with no elements is -legal in C++ -illegal in C++ -automatically furnished with one element whose value is set to zero -automatically furnished with one element, the null terminator -None of these

illegal in C++

This following statement shows an example of ________. int grades][ ] = {100, 90, 99, 80}; -implicit array sizing -an illegal array declaration -default arguments -illegal array initialization -None of these

implicit array sizing

Upon exiting a loop that reads values into an array, the variable used as a(n) __________ to the array will contain the size of that array.

index

With pointer variables you can ________ manipulate data stored in other variables. -indirectly -All of these -None of these -never -seldom

indirectly

A(n) ________ can be used to specify the starting values of an array. -initialization list -array name -subscript -element -None of these

initialization list

Which of the following is a valid C++ array definition? -int array[0]; -float $payments[10.23]; -int numbers[5.6]; -int scores[25]; -None of these

int scores[25];

What is wrong with the following code? int *iptr = &ivalue; int ivalue;

iptr cannot be initialized with the address of ivalue because ivalue is defined after iptr

To determine whether a character entered is a letter of the alphabet, use the ________ function. -isdigit -fromkeyboard -isalpha -alpaok -None of these

isalpha

To test whether a character is a numeric digit character, use the ________ function. -isdigit -None of these -notAlpha -isnumber -isnumeric

isdigit

To test whether a character is a printable character, use the ________ function. -isprintok -isprintable -None of these -isoktoprint -isprint

isprint

Which of the following will return true if the argument is a printable character other than a digit, letter, or space? -ispunct -isprint -isnotdls -None of these -ischar

ispunct

To determine whether a character entered is whitespace, use the ________ function. -isblank -iswhite -isspace -None of these -iswhitespace

isspace

It is ________ to pass an argument to a function that contains an individual array element, such as scores[3]. -illegal in C++11 -legal in C++ -not recommended by the ANSI committee -not good programming practice -None of these

legal in C++

Not all arithmetic operations can be performed on pointers. For example, you cannot ________ or ________ pointers. -increment, decrement -add, subtract -multiply, divide -+=, -= -None of these

multiply, divide

To input, process, or output every item in an n-dimensional array, you need ____ nested loops.

n

To pass an array as an argument to a function, pass the ________ of the array. -name -value of the first element -contents -size, expressed as an integer -None of these

name

In C++ a C-string is a sequence of characters stored in consecutive memory, terminated by a -space -period -semicolon -None of these -null character

null character

The ________ is automatically appended to a character array when it is initialized with a string constant. -None of these -number of elements -null terminator -value of the first element -array name

null terminator

In C++11, the ________ keyword was introduced to represent address 0. -weak_ptr -nullptr -NULL -None of these -shared_ptr

nullptr

A two-dimensional array can have elements of ________ data type(s). -two -four -any number of -one -None of these

one

After the code shown executes, which of the following statements is TRUE? int numbers[] = {0, 1, 2, 3, 4}; int *ptr = numbers;ptr++; -ptr will hold the address of numbers[1] -this code will not compile -ptr will hold the address of the second byte within the element numbers[0] -ptr will hold the address of numbers[0]

ptr will hold the address of numbers[1]

A two-dimensional array can be viewed as -rows and columns -arguments and parameters -increments and decrements -All of these -None of these

rows and columns

Given the following declaration, where is the value 77 stored in the scores array? int scores[] = {83, 62, 77, 97, 86} -scores[0] -scores[1] -scores[2] -scores[3] -scores[5]

scores[2]

To help prevent memory leaks from occurring in C++11, a ________ automatically deletes a chunk of dynamically allocated memory when the memory is no longer being used. -None of these -null pointer -dereferenced pointer -smart pointer

smart pointer

A function may return a pointer but the programmer must ensure that the pointer -still points to a valid object after the function ends -has not previously been returned by another function -was received as a parameter by the function -None of these -has not been assigned an address

still points to a valid object after the function ends

The following statement ________ cin >> *num3; -is illegal in C++ -None of these -stores the keyboard input in the variable num3 -stores the keyboard input into the variable pointed to by num3 -stores the keyboard input into the pointer num3

stores the keyboard input into the variable pointed to by num3

The ________ function concatenates the contents of one C-string with another C-string. -stradd -strcopy -strcat -strappend -None of these

strcat

The ________ function concatenates the contents of one C-string with another C-string. -strcat -None of these -stradd -strappend -strcopy

strcat

An array of string objects that will hold five names would be declared with which of the following statements? -string names[5]; -string names(5); -string names 5; -String[5] = names;

string names[5];

The function that accepts a pointer to a C-string as an argument and returns the length of the C-string, not including the null terminator is -strlen -None of these -countstring -numchar -strlength

strlen

The function that accepts pointers to two C-strings and an integer argument that indicates how many characters to copy from the second string to the first is -strintcpy -strcpy -copystring -strncpy -None of these

strncpy

By using the same ________ you can build relationships between data stored in two or more arrays. -arguments -array name -subscript -None of these -data types

subscript

When you work with a dereferenced pointer, you are actually working with -a copy of the value pointed to by the pointer variable -None of these -the actual value of the variable whose address is stored in the pointer variable -a variable whose memory has been allocated

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

What will the following code output? int number = 22; int *var = &number; cout << var << endl; -an asterisk followed by 22 -an asterisk followed by the address of number -the address of number -22

the address of number

If a variable uses more than one byte of memory, for pointer purposes its address is -the address of the first byte of storage -the address of the last byte of storage -the address of the second byte of storage -the average of all the addresses used to store that variable -None of these

the address of the first byte of storage

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 -the value pointed to by the first is less than the value pointed to by the second -the value pointed to by the first is greater than the value pointed to by the second -the first variable was declared before the second variable -None of these

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

In C++11, assuming mychar is a char variable and mystring is a string, what is the value of mychar after the following statement executes? mychar = mystring.front(); -the first character of mystring -this will cause a compiler error -nothing, the function is missing an argument -the ASCII value of the first character of mystring

the first character of mystring

If you are using an older computer that does NOT support the C++11 standard, you should initialize pointers with -the null terminator '\0' -None of these -the integer 0 or the value NULL -Any of these -a nonzero value

the integer 0 or the value NULL

What will the following statement output? cout << &num1; -the number 1 -the value stored in the variable named num1 -None of these -the memory address of the variable named num1 -the string &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 counter -the i variable -an iterator -the range variable -None of these

the range variable

Which of the following defines a unique_ptr named uniq that points to a dynamically allocated int? -unique_ptr int( new uniq ); -None of these -unique_ptr uniq( new int ); -unique_ptr float( new int ); -unique_ptr int( new int );

unique_ptr uniq( new int );

An element of a two-dimensional array is referred to by -the row subscript of the element followed by the column subscript of the element -None of these -the array name followed by the column number of the element -a comma followed by a semicolon -the row subscript of the element followed by the array name

the row subscript of the element followed by the column subscript of the element

Assuming ptr is a pointer variable, what will the following statement output? cout << *ptr; -None of these -the address of the variable whose address is stored in ptr -the string "*ptr" -the address of the variable stored in ptr -the value stored in the variable whose address is contained in ptr

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

The ________ function will change a character argument from uppercase to lowercase. -atoi -islower -toupper -tolower -None of these

tolower

The arguments of the strcpy function are -None of these -two addresses -one array and one pointer -three pointers -two C-strings

two addresses

Which of the following defines a unique_ptr named uniq that points to a dynamically allocated int? -unique_ptr uniq( new int ); -unique_ptr int( new uniq ); -None of these -unique_ptr uniq( new int ); -unique_ptr int( new int );

unique_ptr uniq( new int );

What is the result after the following statement executes? char var1 = tolower('A'); -var1 stores the character value 'A' -the character A is output to the monitor -var1 stores the ASCII value for lowercase 'a' -None of these -the character a is output to the monitor

var1 stores the ASCII value for lowercase 'a'

Which statement correctly uses C++11 to initialize a vector of ints named n with the values 10 and 20? -vector n<int>(10, 20); -vector<int> n = {10, 20}; -vector<int> n {10, 20}; -int vector n ({10}, {20});

vector<int> n {10, 20};

Dynamic memory allocation occurs -when a new variable is created by the compiler -when a pointer is assigned an incorrect address -when a pointer fails to dereference the right variable -None of these -when a new variable is created at runtime

when a new variable is created at runtime

If you leave out the size declarator in an array definition -you must furnish an initialization list -you are not required to initialize array elements -all array elements default to zero values -your array will contain no elements -None of these

you must furnish an initialization list


Kaugnay na mga set ng pag-aaral

AP Gov Unit 4: Political Culture

View Set

Global Issues Section 1: Key Actors on the World Stage Quiz Questions

View Set

The Utilitarian John Stuart Mill

View Set

World Civ - The French Revolution

View Set

The Scientific Method Study Guide

View Set