CS150 Final Exam

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

Which line in the function "skeleton" below contains an error? #include "digits.h" // 1. int firstDigit(int n) // 2. { // 3. return ""; // 4. } // 5.

#4

Assume c is a char variable. What value s stored in the variable a? string s{"guten tag"}; auto len = s.size(); auto a = s.front(); s.at(len) = a; s[len] = c;

'g'

Which returns the last pixel on the first row of this image? Pixel *p; // address of pixel dataint w, h; // width and height of image* - p + w - 1 - None of these are correct - *p + w - 1 - *(p + w - 1) - *(p + w) - 1

*(p + w - 1)

What happens here? (Carefully check each operator and semicolon.) int y = 4; if (y < 0); y = -y; cout << y << endl; - Runtime error - You Answered 4 - Syntax error - Output is undefined. - -4

-4

Which lines create the C-string "hello"? 1. char s[10] = "hello"; 2. char s[10] = {'h','e','l','l','o'}; 3. char s[] = {'h','e','l','l','o','0'}; 4. char s[5] = "hello"; 5. char s[] = "hello"; - 1, 3 - 1, 5 - 1, 2, 5 - All of them - 1, 2, 3, 5

1, 2, 5

What happens here? char s[50] = "CS150"; strcat(s, "CS50"); cout << s << endl; - "CS50" - "CS500" - Crashes when run. - Undefined behavior - "CS150CS50"

"CS150CS50"

Assume a is 20 and b is 21; what prints? // 0123456789'123456789'123 string s = "The elephant in the room"; cout << s.substr(a, b) << endl; - Runtime error - "room" - "room - "r"

"room"

What is printed here? (Assume all includes have been added. Assume 4-bytes per int, 8 bytes per pointer.) size_t len(const int a[]) { return sizeof(a) / sizeof(a[0]);} int main(){ int a[] = {2, 4, 6, 8}; cout << len(a) << endl;} - 2 - Does not compile - 4 - 1

2

Below is a cumulative algorithm using an array and an iterator-based loop. What is printed? (Assume all includes have been added, etc.) double average(const int *beg, const int *end){ double sum = 0; size_t count = end - beg; while (beg != end) sum += *beg++; return sum / count;} int main(){ int a[] = {2, 4, 6, 8}; cout << average(begin(a), end(a) - 1) << endl;} - 4 - 6 - Does not compile - 5 - Endless loop when run; likely crashes.

4

Which line compiles, but crashes when run? int main(){ vector<int> v{1, 2, 3}; auto size = v.size(); cout << v.back() << endl; // 1. cout << v.front() << endl; // 2. cout << v.at(0) << endl; // 3. cout << v.at(size) << endl; // 4. cout << v.pop_back() << endl; // 5.}

4

Which line throws an exception because of range checking? 1. string s = "holey moley"; 2. auto len = s.size(); 3. auto a = s.front(); 4. s.at(len) = a; 5. s[len] = 'c'; - 3 - none of these - 2 - 4 - 5

4

What prints? Assume 4 bytes per int.int a[][2] = {0}; cout << sizeof(a) << endl; - Illegal declaration. Does not compile. - 12 - 8 - 16 - 4

8

"Use the insertion operator? What in Sam Hill is the insertion operator?" Do you know?

<<

Assume that the user enters: Steve 3.5 68 What value is stored in gpa? - .5 - 3.5 - 68 - program crashes - undefined

5

What is true about an uninitialized pointer? - Dereferencing it is safe, but has no effect. - Dereferencing it is undefined behavior - Dereferencing it will cause a program crash - None of these are true - It is set to the nullptr value

Dereferencing it is undefined behavior

(T/F) An undeclared error message is a linker error.

False

(T/F) Calling a template function like to_string<int>(3.5) is known as implicit instantiation.

False

(T/F) Function overloading lets you call a single function in several different ways.

False

(T/F) Functions with generic parameters may use the keyword class or the keyword struct for their type parameters.

False

(T/F) Implementation files must explicitly qualify each name from the standard library with std::

False

(T/F) In a while loop, (condition) is followed by a semicolon.

False

(T/F) The line: ifstream in("x"); throws a runtime exception if a file x cannot be found.

False

(T/F) The return value of the getline() function is a string object.

False

(T/F) To test if an I/O operation succeeded you must explicitly call the stream's fail() member function.

False

Given the following structure and variable definitions, which data members are uninitialized? struct Employee { long empID{0}; std::string lastName; double salary{0}; int age = 0;}; Employee bob; - lastName - empID - None of them (does not compile) - None of them (compiles) - salary - age

None of them (compiles)

Which line fails to work correctly? template <typename T>void print(const T& item) { cout << item << endl;} - print("hello"); - print(2 + 2); - None of these - print(3 + 2.2); - print(string("goodbye"));

None of these

void f(const vector<int>& v){ v.at(0) = 42;} int main(){ vector<int> x{1, 2, 3}; f(x); cout << x.at(0) << endl;} - 42 - Nothing; compile-time error. - Nothing; run-time error. - 1 - Nothing; linker error

Nothing; compile-time error.

The file temp.txt contains "Orange Coast College". What prints?ifstream in("temp.txt"); char c; while (in.get(c)){ if (isupper(c)) cout << toupper(c);} - oRANGE cOAST cOLLEGE - ORANGE COAST COLLEGE - occ - range oast ollege - OCC

OCC

What is printed when this runs? int a = 3; int b = ++a - a++; cout << "b-> " << b << endl; - 0 - 2 - 1 - Anything at all because this operation is undefined

Anything at all because this operation is undefined

What prints when you enter 2? int which; cin >> which; cout << "The elephant in the room "; if (which % 2) cout << "is white!" << endl; else cout << "is pink!" << endl; - None of these - The elephant in the room is pink! - The elephant in the room is white! - The elephant in the room is white! The elephant in the room is pink!

The elephant in the room is pink?

(T/F) A process filter does something to the characters it encounters.

True

(T/F) A state filter learns something about the stream by examining characters.

True

(T/F) A token is a "chunk of meaningful data".

True

(T/F) Counting the number of words in input by counting word transitions is an example of a state filter.

True

(T/F) Default arguments let you call a single function in several different ways.

True

(T/F) If an input stream's file is missing when you try to open it, its fail()member function returns true.

True

(T/F) Implementation files may use the statement using namespace std;

True

(T/F) Overloaded functions have the same name but different parameter types.

True

(T/F) Structures data members may each have a different type.

True

(T/F) This is the correct syntax for a C++ scoped enumeration.enum class WEEKEND {SUNDAY, SATURDAY=6};

True

(T/F) To read a line of text, you include the header file <string>.

True

(T/F) When passing a structure variable to a function, use non-const reference if the intent is to modify the actual argument.

True

(T/F) You may create a structure variable as part of a structure definition.

True

(T/F)An undefined error message is a linker error.

True

(T/F)Without try and catch, the throw statement terminates the running program.

True

Assuming str is a string object, does this correctly test if strconsists of the characters "quit" in C++? if (str == "quit") . . . - True - False

True

What kind of error is this? ex1.cpp:6:12: error: no viable conversion from 'int' to 'string' string a = 15; - None of these - Linker error (something is missing when linking) - Runtime error (throws exception when running) - Operating system signal or trap - Compiler error (something is missing when compiling) - Syntax error (mistake in grammar) - Type error (wrong initialization or assignment)

Type error (wrong initialization or assignment)

What does this function do? double mystery(const double a[], size_t len) { double x = 0; for (size_t i = 0; i < len; i++) if (a[i] < x) x = a[i]; return x;} - Returns the largest number in the array - Does not compile - Returns the smallest number in the array - Undefined. Depends on the input.

Undefined. Depends on the input.

What is a common pointer error? - Using a pointer without first initializing it - Setting a pointer value to nullptr - You Answered Dereferencing a pointer - Assigning a new value to a pointer - Using indirection on a pointer

Using a pointer without first initializing it

What is printed? template <typename T>ostream& mystery(ostream& out, const T* p, size_t n) { out << '['; if (n) { out << p[0]; for (size_t i = 1; i < n; i++) out << ", " << p[i]; } out << "]"; return out;}. . . int a[] = {1,2,3,4,5,1}; mystery(cout, a, sizeof(a) / sizeof(a[0])) << endl; - [1, 2, 3, 4] - [1, 2, 3] - None of these or undefined output. - [1, 2, 3, 4, 5, 1] - [1, 2, 3, 4, 5]

[1, 2, 3, 4, 5, 1]

What is stored in data after this runs? vector<int> data{1, 2, 3};data.back(); - [] - [2, 3] - [1, 2, 3, 0] - None of these - [1, 2] - [1, 2, 3]

[1, 2, 3]

What is printed when this runs? int main() { int a = 3, b== ++a; cout << "a->" << a << ", b->" << b << endl; } - a->4, b->3 - a->4, b->4 - Anything, this is undefined behavior. - This is a syntax error.

a -> 4, b-> 4

Value passed to the function when it is invoked

arguments

In the classic for loop, loop control variables going from 0 to less-than n are said to employ: - necessary bounds - asymmetric bounds - None of these - intentional bounds - symmetric bound

asymmetric bounds

The block that implements the function's actions

body

Below is a declaration for a partially-filled array. What is the correct prototype for a function delete() that deletes the element at position pos in the array, shifts the remaining elements left, and returns true if successful?const size_t MAX = 100; double nums[MAX]; size_t size = 0; - None of these - bool delete(const double a[], size_t& size, size_t pos); - bool delete(double a[], size_t size, size_t pos); - bool delete(double a[], size_t& size, size_t pos); - bool delete(double a[], size_t MAX, size_t& pos);

bool delete(double a[], size_t& size, size_t pos);

In a library the interface file: - consists of function definitions - consists of instructions that produce the executable - None of these - consists of declarations or - prototypes - consists of function calls

consists of declarations or prototypes

In a library, the client or test program: - None of these - consists of function definitions - You Answered consists of - instructions that produce the executable - consists of function calls - consists of declarations or prototypes

consists of function calls

Assume that ppi correctly points to pi. Which line prints the address of ppi? int main(){ double pi = 3.14159; double *ppi; // code goes here // code goes here} - cout << &pi; - cout << *ppi; - cout << &ppi; - None of these - cout << ppi;

cout << &ppi;

Which of these lines correctly prints 3? struct S { int a = 3; double b = 2.5;}; S obj, *p = &obj; - cout << (*p).a << endl; - cout << *p.a << endl; - cout << p.a << endl; - cout << *(p.a) << endl; - cout << *(p).a << endl;

cout << (*p).a << endl;

Which statement displays the element appearing in the second row and the third column? - cout << a[3][2]; - cout << a[2][1]; - None of these - cout << a[1][2]; - cout << a[2][3];

cout << a[1][2];

Examine the following code (which is legal). Which statement is illegal (given only this code)? struct Money { int dollars{0}, cents{0}; } m1, m2; - if (m1.cents != m2.dollars) . . . - m2.cents++; - m1 = m2; - cout << m1 << endl;

cout << m1 << endl;

What is the equivalent array notation? int dates[10]; cout << (*dates) + 2 << endl; - dates[0] + 2 - dates[2] - dates[0] + 4 - dates[2] + 2 - &dates[2]

dates[0] + 2

- Associates a name with a type - Read a value and store it in a varaible - Copy a new value into an existing variable assign - Allocates space for a variable define - Provides a starting value when a variable is created initialize - A named storage area that holds a value variable

declare input assign define initialize variable

Specifying the function name, type and parameter types.

declaring

Call a single function in several different ways by providing _______: - reference parameters - default parameters - default arguments - mandatory arguments - overloaded arguments

default arguments

Specifying the calculation fractions that occur when the function is used

defining

Given the overloaded functions prototypes and the variable definition below, which of the function calls will fail to compile? int f(int&); int f(int); int f(int, int); int a = 7; - None of these fail to compile - f(a); - f(2.0); - f(3) - f('a', 'b')

f(a);

Given the overloaded functions prototypes and the variable definition below, which of the function calls will fail to compile? int f(int&); int f(int); int f(int, int); int a = 7; - f(a); - None of these fail to compile - f(2.0); - f(3); - f('a','b')

f(a);

Which prototype(s) in the following header file are syntactically correct (legal)? #ifndef EXAMPLE_H #define EXAMPLE_H #include <string> string f1(int a); int f2(double); void f3(std::string& s, int n); double f4(); #endif

f3 f4 f2

What prints? string s("hello"); try { if (s.size() > 2) throw s.size(); if (islower(s.back())) throw s.back(); if (s == "hello") throw string("hello"); s.at(s.size()) = 'x'; cout << "one\n";} catch (const int& e) { cout << "two\n"; } catch (const string& e) { cout << "three\n"; } catch (exception& e) { cout << "four\n"; } catch (...) { cout << "five\n"; } - Undefined - two - four - one - five - three

five

What manipulator can you use to ensure that his large floating-point number appear using regular decimal notation - hex - decimal - fixed - setw - setprecision - scientific

fixed

A function that calculates and returns a value

fruitful function

A named block of code that carries out an action or calculates a value

function

Look at the problem statement below. The _________ of the loop is to count the number of characters in a sentence. How many characters are in a sentence? Count the characters in a string until a period is encountered. If the string contains any characters, then it will contain a period. Count the period as well. - None of these - bounds - plan - goal

goal

An idiom is a short way of describing a common convention. Identify this idiom. if (n % 2 == 1) cout << "Odd" << endl; - multiple selection - alternative action - guarded action - primed decision - short-circuit decision - none of these are correct

guarded action

This code: int * f() { int a[] = {1, 2, 3}; return &a[1];} - has a dangling pointer - has a double delete - has a syntax error - None of these - has a memory leak

has a dangling pointer

This code: void f() { int *p = new int[3]{rand(), rand(), rand()}; if (p[1] != 0 && p[2] != 0) delete[] p; cout << p[0] / p[1] / p[2] << endl;} - has a syntax error - None of these - has a dangling pointer - has a double delete - has a memory leak

has a dangling pointer

One-way, independent decision use: - switch - if - if...if...else...else - if...else...if...else - if...else

if

After opening the input stream in, which of these cannot be used to see if the file was successfully opened? - if (in.bad()) {/* couldn't open */} - if (in.good()) {/* opened ok */} - if (in) { /* opened ok */ } - if (in.fail()) {/* couldn't open */} -if (in.opened()) {/* opened ok */}

if (in.opened()) {/* opened ok */}

Examine this code. Assume that there are no logic errors. Which is the best prototype? int age; string name = read("Enter your name, age: ", age); - string read(string, int); - string read(const string&, int&) - None of these - string read(const string&, int) - string read(const string, int&)

string read(const string&, int&)

If f() needs to change the argument passed here, the parameter must be declared as: void f( . . . str); int main(){ string s = "hello"; f(s);} - const string - const string& - string - string& - It is not possible for f() to change the argument passed here.

string&

Below is a cumulative algorithm using an array and a range-based loop. What is printed? (Assume this is inside main() with all includes, etc.) int a[] = {2, 4, 6, 8}; int sum = 0; for (auto e : a) sum =+ e; cout << "sum->" << sum << endl; - Compiles and runs, but results are undefined. sum->20 - Does not compile. Cannot use range-loop on arrays. - Does not compile; e is undefined. - sum->8

sum->8

Question #28 Mid- 01

thanks

- Shorthand assignment - Post increment - Undefined behavior - Widening conversion - Pre decrement - Chained assignment - Narrowing conversion - Mixed-type expression

y += z; x++; x = z++ - ++z; double a = y; --z; x = y = z = 10; z = 3.15; auto v = x*2.3;

Examine the loop plan from your reader below. Line # 5: 1. Goal: count the characters in a sentence ending in a period 2. Given: the variable str is a string (may be empty) 3. Let counter = -1 4. If str has any characters Then 5. Let counter = 0 - is the loop bounds - None of these - advances the loop - is a goal precondition - is a bounds precondition

is a goal precondition

Which of the following loop patterns are used here? string s{"hello CS 150"}; for (auto e : s){ if (toupper(e)) out.put('x');} - sentinel loop - limit loop - counter-controlled loop - primed loop - data loop - iterator or range loop - loop-and-a-half - inline test

iterator or range loop

Which operator is used to see if all of a set of conditions is true? - logical not - conditional operator - equality - logical or - none of these - logical and

logical and

Assume that name is a string object. Which of these expressions are legal? - name == "sally" - name = "sally" + name - name += "fred" - name = name + 777 - name < "bob" - "sally" += name - name.equals("bob") - Correct Answer name += 'X'

name == "sally" name = "sally" + name name += "fred" name < "bob" name+= 'X'

The variable *p: void f(){ int *p = new int{};} - stores a memory address - is undefined. Code does not compile. - is uninitialized - stores the value 0 in all versions of C++ - stores the value 0 in C++11 only

stores the value 0 in C++11 only

The variable *p: void f(){ int *p = new int(42);} - stores the value 42 in C++11 only - is uninitialized - stores a memory address - is undefined. Code does not compile. - stores the value 42 in all versions of C++

stores the value 42 in all versions of C++

How do you call the function shown here? string square(int a) { return to_string(a * a); } - All of these are legal. - None of these are legal. - int a = square(4); - string a = square(42); - string a; a.square(3); - double a = square(4.0);

string a = square(42);

What prints? int cnt = 0, a[4][5]; for (int i = 0; i < 5; i++) for (int j = 0; j < 4; j++) a[j][i] = cnt++; cout << a[3][2] << endl; - 8 - 14 - 9 - 11 - 19

11

What does this filter do? bool printing = false; char ch; while (cin.get(ch)) { if (printing) cout.put(ch); if (ch == '\n') printing = !printing; } - Removes all of the newlines from a text file - Prints every other line of text, starting with the first - None of these - Prints every other line of text, starting with the second

Prints every other line of text, starting with the second

What does this filter do? char ch; while (cin.get(ch)) { if (isalpha(ch) || isdigit(ch) || isspace(ch)) cout.put(ch);} - None of these - Prints all characters from input - Prints only alphanumeric characters and spaces from input - Prints only non-alphanumeric characters from input

Prints only alphanumeric characters and spaces from input

Which of these statements apply to C++? - Produces native code that runs on the CPU - Automatically catches errors like array out of bounds. - Low-level language - Compiles to bytecode - More efficient than Java or Python - Compiles to native code - Interpreted by a virtual machine

Produces native code that runs on the CPU, More efficient than Java or Python, Compiles to native code

What does this filter do? char ch; while (cin.get(ch)){ if (isspace(ch)) continue; cout.put(ch);} - Prints only spaces - Removes all spaces from input; prints a single line of output - Removes all spaces from input; prints each line separately - None of these

Removes all spaces from input; prints a single line of output

Assume a is 14 and b is 10; what prints? string s{"feed the fish"}; cout << s.substr(a,b) << endl; - Runtime error - "h" - "" - does not compile

Runtime error

What kind of error is this? terminate called after throwing an instance of 'std::out_of_range' - Runtime error (throws exception when running) - Linker error (something is missing when linking) - Compiler error (something is missing when compiling) - Type error (wrong initialization or assignment) - Operating system signal or trap - None of these - Syntax error (mistake in grammar)

Runtime error (throws exception when running)

What prints? void fn(int, double, double&) { cout << "A" << endl; } void fn(int, int, double&) { cout << "B" << endl; } void fn(int, int, double) { cout << "C" << endl; } void fn(int, int, int) { cout << "D" << endl; } int main(){ fn(1, 2, 3, 4);} - Syntax error: no candidates - B - A - C - Syntax error: ambiguous - D

Syntax error: no candidates

Which area of memory is your program code stored in? - Text - Uninitialized Data - Initialized Data - Stack - Heap

Text

Question #17 Mid-01

Thanks

Question #18 Mid- 01

Thanks

You got this!

Thanks

Below is a declaration for a partially-filled array. What is the correct prototype for a function insert() that inserts a new element at position pos in the array, shifts the remaining elements right, and returns true if successful?const size_t MAX = 100;double nums[MAX];size_t size = 0; - bool insert(double a[], size_t size, size_t MAX, double e, size_t pos); - bool insert(double a[], size_t MAX, double e, size_t pos); - None of these - bool insert(double a[], size_t& size, size_t MAX, double e, size_t pos); - bool insert(double a[], size_t& size, double e, size_t pos);

bool insert(double a[], size_t& size, size_t MAX, double e, size_t pos);

Look at the problem statement below. The__________ of the loop is that a period was encountered. How many characters are in a sentence? Count the characters in a string until a period is encountered. If the string contains any characters, then it will contain a period. Count the period as well. - None of these - plan - bounds - goal

bounds

What does this filter do? char ch; while (cin.get(ch)) { if (isspace(ch) && isspace(cin.peek())) continue; cout.put(ch);} - Compresses spaces in a line and single-spaces lines of input - Compresses spaces to a single space only - None of these - Single spaces input lines only

compresses spaces in a line and single-spaces lines of input

Executing, running or invoking the function

calling

In a sequence of try/catch blocks, the last catch block of that sequence should be ____. - catch(int x){ } - catch(str){ } - catch(...){ } - catch(exception){}

catch(...){ }

Which of the following blocks is designed to catch any type of exception? - catch(){ } - catch(*){ } - catch(exception){ } - catch(...){ }

catch(...){ }

Which of these prototypes is the best one to use in this circumstance? int main(){ string str{"To be or not to be."}; cout << "Most common letter is " << mostCommon(str) << endl;} - char mostCommon(const string&); - char mostCommon(string); - char mostCommon(const string); - char mostCommon(string&); - Any of these are fine. - None of these are correct

char mostCommon(const string&);

Which line opens the file input.txt for reading? - fstream in("input.txt"); - ifstream in("input.txt"); - iostream in = "input.txt"; - istream in("input.txt"); - istream in = "input.txt";

ifstream in("input.txt");

This loop: char c; while (in.get(c)){ cout << c << endl;} - illustrates raw character I/O - illustrates token-based stream processing - has a syntax error - illustrates line-based stream processing - is an endless loop

illustrates raw character I/O

Which of the following loop patterns are used here?int upper = 0;char ch;while (in.get(ch)) { if (ch >= 'A' && ch <= 'Z') upper++;} - primed loop - limit loop - iterator or range loop - inline read and test - loop-and-a-half - counter-controlled loop - sentinel loop - data loop

inline read and test data loop

Which of these is a 2D array? - int *b[2]; - int d[][] - int c[2][2]; - All of these - int a[][2];

int c[2][2]

This compiles, runs and prints 12. What is the correct parameter declaration for x? int x = 6;multiply(x, 2);cout << x << endl; - int x - const int& x - int& x - None of these

int& x

The class ____ is designed to deal with illegal arguments used in a function call. - illegal_argument - bad_argument - invalid_call - invalid_argument

invalid_argument

Examine the loop plan from your reader below. Line #6: 1. Goal: count the characters in a sentence ending in a period 2. Given: the variable str is a string (may be empty) 3. Let counter = -1 4. If str has any characters Then 5. Let counter = 0 6. Let current = first character in str

is a bounds precondition

The value for the variable b is stored:int a = 1;void f(int b){ int c = 3; static int d = 4;} - on the stack - on the heap - in the static storage area - in the CPU machine registers - The example does not provide enough information

on the stack

Different functions that have the same name, but take different arguments, are said to be: - overloaded - derived - overridden - covariant - default

overloaded

Variables define along with the function to receive input

parameters

Given the following structure and variable definitions which statements are legal?struct Money { int dollars{0}; int cents{1}; }; Money payment; - payment.cents = 5; - None of them - payment{1} = 5; - Money{1} = Money{0}; - cout << Money.dollars; - cout << payment.dollars;

payment.cents = 5; cout << payment.dollars;

Look at the problem statement below. The _________ of the loop is read a character and increment a counter. How many characters are in a sentence? Count the characters in a string until a period is encountered. If the string contains any characters, then it will contain a period. Count the period as well. - plan - goal - none of these - bounds

plan

A function that carries out an action instead of calculating a value

procedure

Another name for a function declaration

prototype

The variable p: void f(){ int *p = new int;} - is uninitialized - stores the value 0 - None of these - stores a memory address

stores a memory address

- Append output to a file named z - Discard both output and errors rm - Write output to a new file named - Read the input from the file named z - Write errors to a new file named z - Send the output to the input of the program named z

pwd >> z rm x >/dev/null 2>&1 z pwd > z cat < z cat x 2 > z date | z

Produces a value when the function is invoked

return statement

Given the following structure and variable definitions, which data members are default initialized? struct Employee { long empID; std::string lastName; double salary; int age;}; Employee bob{777, "Zimmerman"}; - None of these - You Answered empID - Correct Answer age - lastName - salary

salary

Which expression returns the number of countries? string countries[] = {"Andorra", "Albania", . . . }; - sizeof(countries) - None of these - sizeof(countries) * sizeof(countries[0]) - sizeof(countries) / sizeof(countries[0]) - len(countries)

sizeof(countries) / sizeof(countries[0])

Where are the characters "Hello" stored in memory? char s1[1024] = "Hello"; void f(){ const char *s2 = "Goodbye"; char s3[] = "CS 150";} - stack - heap - None of these - static storage area (read-only) - static-storage area (read/write)

static-storage area (read/write)

What prints? string s("hello"); try { if (s.size() > 5) throw s.size(); if (isupper(s.back())) throw s.back(); if (s == "hello") throw string("hello"); s.at(s.size()) = 'x'; cout << "one\n";} catch (const string& e) { cout << "two\n"; } catch (exception& e) { cout << "three\n"; } catch (...) { cout << "four\n"; } - Undefined - one - three - four - two

two

In the classic for loop, which portion of code is not followed by a semicolon? - update expression - initialization statement - condition expression - None of these

update expression

This compiles, runs and prints 5,4. What is the correct prototype? int a = 4, b = 5;swap(a, b);cout << a << "," << b << endl; - void swap(int& a, int& b); - void swap(const int& a, const int& b); - int swap(int a, int b); - None of these

void swap(int&a, int& b);

Below is a partially-filled array. If you are adding elements to this array in a loop, what is the correct loop bounds condition? const size_t MAX = 100; double nums[MAX]; size_t size = 0; - while (size < MAX) . . . - while (MAX < size) . . . - for (size = 0; size < MAX; size++) . . . - while (size <= MAX) . . . - None of these

while (size < MAX) . . .

What is stored in s after this code runs? string s{"xyzw"}; s.at(2) = 'Y'; - This is illegal because you cannot change the individual characters inside a string object. - xYzw - This is illegal because you cannot have a function on the left-hand side of an assignment. - xyYw - xyzw

xyYw


Kaugnay na mga set ng pag-aaral

TestOut IT Fundamentals - Chapter 1-8

View Set

Biology 12 - Reproductive System

View Set

Chapter 14: The Market Labor and Other Factors of Production

View Set

Quiz Four- "The Nature of Ethical Disagreement" by Charles L. Stevenson

View Set