CS253 Midterm 2 set, CS 253 Midterm the Ultimate Quizlet 1.1

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

What is the first line of a bash script in Linux?

#! /bin/bash

What is the first line of a bash script in Linux?

#!/bin/bash #! /bin/bash #!/usr/bin/bash #! /usr/bin/bash

What header do you need to include in order to use symbols such as cin and cout

#include <iostream>

What is the special variable for argument count in a Bash script?

$#

Consider a bash script, executed like this: Inside the bash script, we want to get the second argument, in this instance, gamma. What is the correct way to do that?

$2

Consider a file that contains exactly these two lines: Each line contains two leading spaces. There are two spaces between alpha and beta. There are no trailing spaces. If the first operation on this newly-opened file is char c; cin.get(c), it will return If the first operation on this newly-opened file is string s; getline(cin, s), s will contain If the first operation on this newly-opened file is string s; cin >> s, s will contain " alpha beta\n gamma\n" .

' '(one space) " alpha beta" (two leading spaces) "alpha"

Match the literal with its type

'a' char "b" const char array o "c"s std::string 42 int 42L long 42ULL unsigned long long 3.4F float 3.4 double 3.4L long double

What type are these literals? (a) "alpha" (b) "beta"s (c) 'x' (d) "y"

(a) array of const char (b)C++ string object (c)char (d)array of const char

Match the C++ I/O stream object to its description. (a)-cout (b)-cerr (c)-clog (d)-cin (e)-coff

(a)- standard output, for normal output (b)- standard error, for error messages, unbuffered (c)- like cerr, but fully buffered (d)- standard input (e)- not a C++ I/O stream object

1. The header file <cstring> defines the symbol [ (a) ] ["c_str", "string", "strlen"] in the [ (b) ] ["std", "global"] namespace. 2. The header file <string.h> defines the symbol [ (c) ] ["string", "c_str", "strlen"] in the [ (d) ] ["std", "global"] namespace. 3. The header file <string> defines the symbol [e] string in the [ (f) ] ["global", "std"] namespace.

(a)- strlen (b)- std (c)- strlen (d)- global (e)- string (f)- std

Consider this code: #include <string>using namespace std; double d; int foo() { string z = "Slartibartfast"; return z.length(); } (a)- d is in (b)- foo is in (c)- string is in (d)- z is in (e)- int is in

(a)- the global namespace (b)- the global namespace (c)- the std namespace (d)- no namespace at all (e)- no namespace at all

Consider this function declaration: void foo(int i, double d, int a[9], string s, vector<int> v); How is each parameter passed to the function? (a)- i (b)- d (c)- a (d)- s (e)- v

(a)- value (b)- value (c)- reference (d)- value (e)- value

Match the code with its description. (a)-cout << 1/0; (b)-cout << sizeof(int); (c)-int a, b; if (&a<&b) cout << 42; (d)-int i=42; i >>= 3; cout << i;

(a)-undefined behavior (b)-implementation defined behavior (c)-unspecified behavior (d)-great code

Consider: vector<double> v = {1.1, 2.2, 3.3, 4.4}; I want to access the third element of v that contains 3.3. How should I do that? -v[2] -v.at(2) -v[3.3] -v.2

- that will work - that will work -that won't work -that won't work

A return value is given after the successful completion of main. what value is given to the invoker?

0

In this code, how many times will foo() be called? for (int i=0; i<5; i++) { static auto v = foo(); cout << v << '\n'; }

1

When this code executes, how many times will foo() be called? for(int i=0; i<5; i++) { static auto v = foo(); cout << v << '\n'; }

1 (with margin 0)

Consider this code: #include <string> using namespace std; double d; int foo() { string z = "Slartibartfast"; return z.length(); } A. the global namespace B. the std namespace C. no namespace at all 1. d is in 2. foo is in 3. string is in 4. z is in 5. int is in

1. d is in the global namespace 2. foo is in the global namespace 3. string is in the std namespace 4. z is in no namespace at all 5. int is in no namespace at all

What output will this code produce? If it will not compile, answer "it will not compile." int main() { cout << fixed << setprecision(2) << 1.23456789; }

1.23

What will this code display?

10 11

What will this code display?

103

What will this code display? int foo() { static int z = 100; return ++z; } int ma‍in() { int a = fοo(); a = foo(); a = foo(); cοut << a << '\n'; } 100 It cannot be determined. 103 102 0 101

103

What will this code display? int foo() { static int z = 100; return ++z; } int main() { int a = foo(); a = foo(); a = foo(); cout << a << '\n'; }

103

What will this code display? cout << ((0xF & 0b11) (8);

11

What will this code produce? void foo(int bill) { const int ted = bill; cout << ted; } int main() { foo(12); foo(34); }

1234

What is the output of this code?

15

What will this code display? cout << dec << 0x12 << '\n'; -It will not compile -12 -18 -10 0x12 -0x12

18

How many arguments can you pass and the function will still compile?

2, 3 or 4

void foo (int a, int b, int c = 10, int d=20); How many arguments can i give to this function without a syntax error?

2, 3 or 4

How many arguments can I give to this function without error?

2, 3, or 4

What will this code display, assuming that the file zork exists, is readable by you, and contains only the three bytes "123"? іfѕtrеаm іn("zоrk"); іnt а, b; іn >> а >> b; іf (іn) соut << 1; іf (іn.bаd()) соut << 2; іf (іn.еοf()) соut << 3; іf (іn.fаіl()) сοut << 4; іf (іn.gооd()) сοut << 5;

34

What will this code produce? string s = "abc"; s += 'd'; s.push_back('e'); cοut << s.length(); 8 It cannot be determined. 5 It won't compile; string has no .length() method

5

What will this code produce? string s = "abc"; s += 'd'; s.push_back('e'); cout << s.length();

5

What is possible output from this code? vector < int > v; //put some data into v cout << v.size() << ' ' << v.max_size() << ' ' << v.capacity();

5 4611686018427387903 8

What will this code produce?d

5678

What will this code display? Assume that a char is one byte class Foo { public: char red[32]; private: char blue[32]; static char green[32]; }; int main() { Foo bar; cout << sizeof(bar); }

64

What will this code display? Assume that a char is one byte.

64

What will this code display? Assume that a char is one byte. class Foo { public: char red[32]; private: char blue[32]; static char green[32]; }; int main() { Foo bar; cout << sizeof(bar); } 32 256 128 64 96

64

What will this code display, when executed?

7

I want to add the output of the ls command to the end of an existing file named stuff. Give a single Bash command to do that.

>>stuff ls

The [[noreturn ]] attribute means:

A function will never return.

The [[noreturn]] attribute means:

A function will never return.

The [[noreturn]] attribute means: A. A function will never return. B. A function always throws an error. C. A function contains an infinite loop. D. A function doesn't contain a return statement. E. A function sometimes throws an error.

A. A function will never return.

A good compiler might complain that zorkmid never gets used in the following code. How would I convince the compiler to stop complaining about that? void dungeon() { int zorkmid = 42; } A. [[maybe_unused]] B. [[not_used]] C. [[unused]] D. [[maybe_used]] E. [[not_unused]] F. [[used]]

A. [[maybe_unused]]

What output will this code produce? Int main() { cout<<uppercase<<hex<<10<<"hello"; }

Ahello

Assume that class A is the friend of class B, and class B is the friend of class C. Therefore:

C and A aren't friends in any way

What is the type of this literal: "beta"s

C++ string object

What version of C++ are we working with?

C++17

What version of C++ will this class focus on?

C++17

Why would this code not work?

C-style arrays don't have methods

In a Makefile, when file Bill depends on file Ted, how does make determine when it's time to recreate Bill from Ted? A. It keeps track of when you edit or remove the file Ted. B. It always recreates Bill from Ted, whether it's strictly necessary or not. C. It checks the modification times of the files. D. make spawns a modified sub-shell, which reports file-modifying commands back to make.

C. It checks the modification times of the files.

Any problem with this code? vector v; v[0] = 34;

Can't write to v[0] when v.size()==0

Which one of the following statements concerning UTF-8 is true? ->All characters require exactly four bytes in memory. ->All characters require exactly two bytes in memory. ->All characters require either two or four bytes in memory. ->All characters require exactly one byte in memory. ->Characters require a variable number of bytes in memory.

Characters require a variable number of bytes in memory.

What does the BASH command cat do?

Concatenate files and print on the standard output

What happens when you try to use .resize(n) on a container that is less than the originally created size?

Content is reduced to its first n elements, removing those beyond and destroying them.

Consider this constructor: Foo(int a, double d) { alpha=a; delta=d; } Which answer is equivalent code, but using a member initialization list? A. Foo(int a, double d) : alpha,delta(a,d) { } B. No change needed—it already uses a member initialization list. C. Foo(int alpha=a, double beta=d) { } D. Foo(int a, double d) : alpha(a), delta(d) { } E. Foo(int a, double d) alpha=a; delta=d; { }

D. Foo(int a, double d) : alpha(a), delta(d) { }

What is the text segment? A. It contains dynamic memory. B. Strings go there. C. Read/write variables go there. D. Program instructions go there.

D. Program instructions go there.

Consider the class Polar, which has two double member variables r and theta. Which of these is a correct copy constructor for Polar? A. Polar(const Polar rhs) : r(rhs.r), theta(rhs.theta) { } B. Polar(Polar rhs) const : r(rhs.r), theta(rhs.theta) { } C. Polar(Polar &rhs) : r(rhs.r), theta(rhs.theta) { } D. Polar(Polar rhs) : r(rhs.r), theta(rhs.theta) { } E. Polar(const Polar &rhs) : r(rhs.r), theta(rhs.theta) { }

E. Polar(const Polar &rhs) : r(rhs.r), theta(rhs.theta) { }

When make is executed in a directory containg only the following Makefile, which commands are executed? alpha: delta echo gamma beta: delta echo epsilon delta: echo pi lambda: echo tau A. echo tau; echo gamma B. echo tau; echo epsilon C. echo pi; echo epsilon D. echo epsilon; echo gamma E. echo pi; echo gamma

E. echo pi; echo gamma

Text is a segment that contains executable code (CPU instructions) that is marked as write-only and then executable.

False

In a non-const method of class Foo, what type is the special symbol this? Foo * Foo & Foo() void Foo

Foo *

Which is the best declara"on for a copy constructor for class German?

German(const German &)

Which is the best declaration for a copy constructor for class German?

German(const German &)

Which is the best declaration for a copy constructor for class German? German(German &other) { *this = other; } German(German) German(const German *) German *new(German &) German(const German &)

German(const German &)

<string.h> defines strlen in the ________ namespace

Global

Who defines what goes into official C++ 2017?

ISO, the International Standards Organization

Consider a Makefile, where foo.cc & foo.h define a class, and main.cc uses that class: Why does the Makefile say that main.o depends on foo.h?

If main() instantiates a Foo object, then it needs to at least know the size of a Foo object.

Consider a Makefile, where foo.cc & foo.h define a class, and main.cc uses that class: Why does the Makefile say that main.o depends on foo.h?

If main() instantiates a Foo object, then it needs to at least know the size of a Foo object.

Consider a Makefile, where foo.cc & foo.h define a class, and main.cc uses that class: prog: main.o foo.o $(CXX) main.o foo.o -o prog main.o: main.cc foo.h $(CXX) -c main.cc foo.o: foo.cc foo.h $(CXX) -c foo.cc Why does the Makefile say that main.o depends on foo.h?

If main() instantiates a Foo object, then it needs to at least know the size of a Foo object.

Consider a small Makefile, where foo.cc & foo.h define a class, and main.cc uses that class. prog: main.o foo.o $(CXX) main.o foo.o -o prog main.o: main.cc foo.h $(CXX) -c main.cc foo.o: foo.cc foo.h $(CXX) -c foo.cc Why does the Makefile say that main.o depends on foo.h? Every object file must depend on one .cc file and one .h file. That is an error—there is no reason for that dependency. All object files must depend on all header files. If main() instantiates a Foo object, then it needs to at least know the size of a Foo object.

If main() instantiates a Foo object, then it needs to at least know the size of a Foo object.

Where is [[fallthrough]] used?

In a switch statement.

Consider this code: int a[10]; cout << a[20]; What will it do? -segmentation violation -It will display an unpredictable value. -It will display zero. -It cannot be determined. -It will throw an error.

It cannot be determined.

Consider this code: int a[10]; cout << a[20]; What will it do?

It cannot be determined.

What will this code produce, when executed?

It cannot be determined.

What will this code produce, when executed? class Fοo { public: Foo(int n) : valu‍e(n*n) { } Foo() { Fοo(10); } int value; }; int main() { Fοo f; cοut << f.value << '\n'; return 0; } 0 It cannot be determined. 100 10*10 10

It cannot be determined.

In a Makefile, when file Bill depends on file Ted, how does make determine when it's time to recreate Bill from Ted?

It checks the modification times of the files.

In a Makefile, when file Bill depends on file Ted, how does make determine when it's time to recreate Bill from Ted? -It keeps track of when you edit or remove the file Ted. -It always recreates Bill from Ted, whether it's strictly necessary or not. -make spawns a modified sub-shell, which reports file-modifying commands back to make. -It checks the modification times of the files.

It checks the modification times of the files.

The standard C header file , defines the func"on exit() What does this tell us about the C++ header file ?

It defines exit in the std namespace.

The standard C header file <stdlib.h>, defines the function exit() What does this tell us about the C++ header file <cstdlib>?

It defines exit in the std namespace.

The standard C header file <stdlib.h>, defines the function exit(). What does this tell us about the C++ header file <cstdlib>?

It defines exit in the std namespace.

What does it mean for a method to be const?

It must not change any non-static class data, or call any non-const class methods.

What will this code do, when executed?

It will display the five characters "Hello".

What will this code do, when executed? int spock[10]; spock[12] = 42;

It will invoke undefined behavior

What will this code produce, when executed?d

It will invoke undefined behavior.

What will this code produce, when executed?dd

It will invoke undefined behavior.

public: Bob (int n) : hammer(n) {} int hammer = 52; }; int main() { Bob b; cout << b.hammer << '\n'; }

It will not compile - Bob has no default constructor

What will this code produce, when executed? class RainbowDash { public: RainbowDash() : company("Hasbro") { } RainbowDash(string c) : company("pony") { } string company = "pegasus"; }; int main() { RainbowDash rd(); cout << rd.company << '\n'; }

It will not compile.

What output will this code produce, when executed?

It will not compile—Bob has no default constructor.

What output will this code produce, when executed? class Bob { public: Bob(int n) : hammer(n) { } int hammer = 52; }; int main() { Bob b; cout << b.hammer << '\n'; }

It will not compile—Bob has no default constructor.

What will this code produce, when executed?

It will throw an error.

Which of these properly describes strerror?

It's a function that takes an errno-like value and returns a string describing the error.

Which of these properly describes errno?

It's an int global that contains a number that corresponds to the most recent error.

Any problems with this code?

It's fine

Any problems with this code? string s = "chimp"; s[2] = 'u'; -'u' should be "u" -String objects must be allocated with new. -It's fine. -You need to use s.at[2] -You can't modify a C++ string

It's fine

Is this code ok? string s = "Hockle & Jeckle"; s[1] = 'e'; cout << s << "\n"; -You can't modify a string. -"\n" must be '\n', since it's a single character. -You can't use [1] to modify a string; must use .at[1] instead. -endl must be used, not '\n' -It's fine.

It's fine

Any problems with this code? string s = "chimp"; s[2] = 'u';

It's fine.

Consider this code: cout << numeric_limits < short > :: max() << '\n'; select the true statement.

Its value cannot be portably determined

Consider this code: Select the true statement.

Its value cannot be portably determined.

Are all C programs valid C++ programs?

Nearly all of them

What is Heckendorns rule?

Never emit a constant error message

What is Heckendorn's rule?

Never emit a constant error message.

What is Heckendorn's rule? -Never emit a constant error message. -Don't read a pointer after using delete on it. -Check values for zero before dividing. -Save errno before using it. -Every error message must contain a file name. -Initialize all variables.

Never emit a constant error message.

Will the following code compile?

No

Could this code produce a division-by-zero error?

No, because the right operand of && is only evaluated if the left operand is a true value.

Could this code produce a division-by-zero error? dds

No, because the right operand of && is only evaluated if the left operand is a true value.

Could this code produce a division-by-zero error? int n = 0; if (n != 0 && 5/n == 3) cout << "Good!\n";

No, because the right operand of && is only evaluated if the left operand is a true value.

Will this code work?

No, there is an invalid conversion from int* to int

Is this code valid? void foo(int n) { constexpr auto c = n; cout << c; }

No; n is not a compile-"me constant

Is this code valid? void foo(int n){ constexpr auto c=n; cout << c; }

No; n is not a compile-time constant

Which of these statements will display 123?

None of other answers is correct.

What is the biggest difference between set & a multi-set?

One stores unique elements while the other does not.

In this code, when will stan() be called?

Only once, during the first call to bob()

In the following code, how often is three() called?

Only once, during the first call to one()

In this code, when will groot() be called?:

Only once, during the first call to rocket().

Consider the class Polar, which has two double member variables r and theta. Which of these is a correct copy constructor for Polar?

Polar(const Polar &rhs) : r(rhs.r), theta(rhs.theta) { }

Consider the class Polar, which has two double member variables r and theta. Which of these is a correct copy constructor for Polar? Polar(const Polar rhs) : r(rhs.r), theta(rhs.theta) { } Polar(Polar rhs) : r(rhs.r), theta(rhs.theta) { } Polar(Polar &rhs) : r(rhs.r), theta(rhs.theta) { } Polar(const Polar &rhs) : r(rhs.r), theta(rhs.theta) { } Polar(Polar rhs) const : r(rhs.r), theta(rhs.theta) { }

Polar(const Polar &rhs) : r(rhs.r), theta(rhs.theta) { }

What goes in the text segment?

Program instructions

What is in the text segment?

Program instructions go there.

What is the text segment? Strings go there. It contains dynamic memory. Read/write variables go there. Program instructions go there.

Program instructions go there.

What will this code do? Assume that an int is 32 bits.

Since 40≥32, the result is not determined.

What will this code do? Assume that an int is 32 bits. int n; // assume that n gets a value. n <<= 40; -Shifts are implemented as rotates, so it's the same as shifting left by 8 (40-32) bits. -This will not compile, because there is no <<= operator. -Since 40≥32, the result is not determined. -This will shift all the bits off the left end, resulting in zero.

Since 40≥32, the result is not determined.

Why do we care about scope of our variables?

Smaller scope is better for code maintenance

What are the 5 memory segments?

Text, Data, BSS, Stack and Heap

For this code: cout << (a() - b()) / c(); Check all the statements that are true.

The func"on b could be called first. The func"on c could be called first. The func"on a could be called first.

Consider the code, what is the scope of the variable named 'variable' ?

The if statement

What will this code produce?

The output cannot be determined

What will this code do, when executed?

The output cannot be portably determined.

What is the best scope for a variable?

The smallest scope that works

Consider this code: for (int i=1; i<1'000'000'000; i++) { flοat *f = new float[100'000'000]; } What will be the result? Since the variable f is declared inside the loop, its destructor will free the memory. The system will run out of memory. No problem. The allocated memory will be freed by the garbage collector.

The system will run out of memory.

Consider this code. What will it do, when executed? int a; cout << a;

This code will invoke undefined behavior

The word "deprecated", in the context of C++ programming means:

This feature is supported today, but that is expected to change.

The word "deprecated", in the context of C++ programming, means:

This feature is supported today, but that is expected to change.

Consider this code: double *dp = new double[45]; //use the dynamically-allocated storage here delete dp; Note that delete, not delete[], was used. How will the system react?

This is undefined behavior, so no particular result is guaranteed.

Consider this code: double *dp = new double[45]; // use the dynamically-allocated storage here delete dp; Note that delete, not delete[], was used. How will the system react?

This is undefined behavior, so no particular result is guaranteed.

Consider this code: int a; cout << a;

This will invoke undefined behavior

Would the following code produce a division by zero error?

This will not produce an error because the left side of the equation did not pass

.capacity() tells us the number of non-null slots in a particular container?

True

Look at the code below, what type of behavior is it?

Undefined

Is this code functional?

Yes, this code works

A compiler might complain that a variable was never used. How would I convince said compiler to stop complaining about that?

[[maybe_unused]]

A good compiler might complain that zorkmid never gets used in the following code. How would I convince the compiler to stop complaining about that? void dungeon() { int zorkmid = 42; } [not_used]] [[not_unused]] [[maybe_used]] [[used]] [[unused]] [[maybe_unused]]

[[maybe_unused]]

A good compiler might complain that zorkmid never gets used in the following code. How would I convince the compiler to stop complaining about that? void dungeon() { int zorkmid = 42; }

[[maybe_unused]]

Given these definitions: Match the following expressions with their types:

a float a float * c float *a not a valid expression *b float *c not a valid expression &a float * &b float ** &c float **

Consider this code: Which one of the following statements is true?

a is in data, b is on the stack, c points to the heap

Consider this code: int a=1; int main() { int b=2; int *c = new int; }

a is in data, b is on the stack, c points to the heap

Consider this orders of evaluation question. What are the possible orders this could get ran?

a, b, c, +, * a, b, +, c, * a, c, b, +, * b, a, c, +, * b, a, +, c, * b, c, a, +, * c, a, b, +, * c, b, a, +, *

What is the type of this literal: "alpha"

array of const char

What will the following code display? cout << "alphabet" + 5;

bet

What will this code display? cout << "alphabet" + 5;

bet

What will this code display? cout << "alphabet" + 5 << '\n'; -bet -alphabey -alphabet5 -flphabet

bet

What is the built-in type that C++ uses for Boolean values?

bool

Consider the run-time efficiency of the different methods of passing parameters in these function signatures: Which one of the following statements is true, for a typical compiler?

calling bravo is fastest

What is the type of this literal: 't'

char

What's the literal type? 'a'

char

How do we fix this code?

const char *p = "Howdy";

What's the literal type? "b"

const char array

Which statement is true?

const says that you can't change it, constexpr says that it doesn't change.

True or False constexpr means the variable never changes const means the variable can't change constexpr is computed at compile time

constexpr means the variable never changes T const means the variable can't change F constexpr is computed at compile time Unknown

Which statement is true?

conts says you cant change it, constexper says that it does not change

I have a source file homeworkishard.cc and I wish to make a backup copy in the file homeworkishard.save. Which BASH command will accomplish that?

cp homeworkishard.cc homeworkishard.save

I have a source file hw1.cc. I wish to make a backup copy in the file hw1.save. Which command will accomplish this? -copy hw1.cc hw1.save -save hw1 -cp hw1.cc hw1.save -cp hw1.cc >hw1.save -save hw1.cc

cp hw1.cc hw1.save

Which of these will display 123?

cο‌u​t‌ ‌<​< ‌t‌о‌_​ѕ‌tr​і‌ng(‌123)​;‌

Consider this code: #include using namespace std; double d; int foo() { string z = "Slartibartfast"; return z.length(); }

d is in Global foo Global string is in std z is in no namespace int is in no namespace

Consider this code: Correct answers No namespace at all the std namespace the global namespace d is in.. foo is in string is in z is in int is in d is in.. foo is in string is in z is in int is in

d is in.. Global foo is in N/A string is in N/A z is in N/A int is in N/A

In a bash script, I want to write the three le!ers "ABC", followed by a newline, to standard output. How do I accomplish this?

echo "ABC"

When make is executed in a directory containg only the following Makefile, which commands are executed? alpha: delta echo gamma beta: delta echo epsilon delta: echo pi lambda: echo tau

echo pi; echo gamma

When make is executed in a directory containing only the following Makefile, which commands are executed?

echo pi; echo gamma

When make is executed in a directory containing only the following Makefile, which commands are executed? alpha: delta echo gamma beta: delta echo epsilon delta: echo pi lambda: echo tau

echo pi; echo gamma

What is the difference between '\n' and endl

endl flushes the output, '\n' does not

What is the difference between '\n' and endl?

endl flushes the output, '\n' does not.

How is endl different from '\n' ?

endl makes a newline then flushes the output, while '\n' makes a newline

What's the literal type? 3.4F

float

Which of these statements convert the contents of the int variable iv to a pointer to a float?

float *fp = reinterpret_cast(iv);

What statement convert the contents of int iv to a pointer to a float?

float *fp = reinterpret_cast<float *>(iv);

Which of these statements convert the contents of the int variable iv to a pointer to a float? float *fp = reinterpret_cast<float *>(iv); float *fp = reinterpret_cast(float *, iv); float *fp = reinterpret_cast<int>(iv); float *fp = dynamic_cast<float *>(iv);

float *fp = reinterpret_cast<float *>(iv);

How is each parameter passed to the function?

i = Value d =Value a = reference s = Value v = Value

Consider this func"on declara"on: void foo(int i, double d, int a[9], string s, vector v); How is each parameter passed to the func"on?

i value d value a reference s value v value

The function time() returns the number of seconds since the start of 1970 on a Linux system. The return type of time() is a time_t, which is an alias for some integer type. You know that 2³¹, or 2147483648, seconds after the start of 1970 falls in the year 2038, which is not that far away, so you are concerned about the representation of time_t on your computer. Which of the following will display "OK" if and only if your computer can represent time past the year 2038?

image is answer

What is a valid signature for main?W

int main(int argc, char *argv[])

Which code fragment correctly reads an int from standard input and writes twice its value to standard output?

int n; cin >> n; cout << n*2;

Which piece of code correctly reads a int from standard input and writes value times 3 to standard output?

int n; cin >> n; cout << n*3;

Match the code with the description: undefined behavior implementation-defined behavior unspecified That code will work int one, two; cout << boolalpha << (&a < &b); cout << 15/0; int i = 3; i <<=1; cout << i; short s = 32767;

int one, two; cout << boolalpha << (&a < &b); = unspecified cout << 15/0; == undefined behavior int i = 3; i <<=1; cout << i; == That code will work short s = 32767; == implementation-defined behavior

I want to declare a variable v, and a reference r, and have the reference refer to the variable. Which statement accomplishes this?

int v, &r=v;

I want to declare a variable v, and a pointer p, and have the pointer point to the variable. Which statement accomplishes this?

int v, *p = &v;

I want to declare a variable v, and a pointer p, and have the pointer point to the variable. Which statement accomplishes this? int v, p = *v; int v, *p = &v; int v, *p = v; int v, &p = v;

int v, *p = &v;

Which is the correct way to cast from const int * to int *?Assume these declarations:

ip = const_cast<int *>(cip);

Consider the code and the namespaces global namespace std namespace int namespace no namespace len is in the: name is in the: number is in the: len is in the: name is in the: number is in the:

len is in the: == Global name is in the: == Std number is in the: == Global

Consider this definition: auto alpha = 42L; What type is the variable alpha? -auto -int -42L -It has no type. -long

long

Consider this definition: auto hamster = 42L What type is the variable hamster?

long

Consider this definition: auto hamster = 42L

long

auto snake = 42; What type is the variable snake

long

Consider this declaration: What type is mutt? What type is jeff?

long * long

How would I the output of the BASH command "ls" to the end of a file named "lists"

ls >> lists

I want to add the output of the ls command to the end of an existing file named stuff. Give a single Bash command to do that.

ls>>stuff

When first creating a C++ you have to give main() what is main() considered?

main is a function

Which statement is true? -main is a constructor -main is optional -main is a function main is a method.

main is a function

Which statement is true? a. main is a constructor b. main is optional c. main is a function d. main is a method

main is a function

Match the C++ I/O stream object to its description. coff

not a C++ I/O stream object

I want to find out how many bits are in a int, not counting the sign. For most modern computers, I expect the value 31. Which of these will produce that value?

numeric_limits<int>::digits

How can we tell how many decimal digits are in an int? Assuming for most modern computers it will be 9, what is the method that will work:

numeric_limits<int>::digits10()

I want to find out how many bits are in a int, not counting the sign. For most modern computers, I expect the value 31. Which of these will produce that value? numeric_limits<int>:‍:digits numeric_limits<int>:‍:digits10() It's not needed—the number of bits in an int is guaranteed by the standard to be 31. numeric_limits<int>:‍:max()

numeric_limits<int>:‍:digits

You want to be able to display an instance of class Foo, as shown here: Foo f; cout << f; What would be the correct declaration for a function to do that?

ostream &operator << (ostream &, const Foo &);

Consider this class: class Foo { public: int id; int ego; private; int superego; }; what access does ego have?

public

Consider this class: What access does ego have?

public

What access does ego have?

public

What is the Bash command for removing a directory and all its files?

rm - r directory

For a standard C++ container named con, match the following expressions to their descriptions: # of elements currently stored in con # of bytes before a null byte is encountered max # of elements that con could possibly ever hold size of the con object in bytes, excluding any dynamic memory # of elements' worth of memory con has currently allocated size(con) con.size() sizeof(con) con.capacity()

size(con) # of elements currently stored in con con.size() # of elements currently stored in con sizeof(con) size of the con object in bytes, excluding any dynamic memory con.capacity() # of elements' worth of memory con has currently allocated

What is a compile-time function that returns the size of an object in bytes?

sizeof()

<cstring> defines strlen in the ________ namespace

std

Which is the INCORRECT statement about strerror?

strerror does not need a header file to function

Define a variable, name, using a string

string name = "Billy Joe";

I want to define a variable prez that contains the name of the first U.S. president. How would I do that?

string prez = "George Washington";

What's the difference between struct and class?

struct defaults to public, class defaults to private

What's the difference between struct and class? struct is only for C programs, class is only for C++ programs struct can't have methods, class can have methods Only struct can have public data members; in a class data must be private struct defaults to public, class defaults to private

struct defaults to public, class defaults to private

Consider this statement: if (auto now = time(nullptr)) What is the scope of the variable now? -the if statement -the rest of the function -now has global scope -the entire function

the if statement

After #include <iostream>, what namespace contains the symbol cout?

the namespace called "std"

What namespace contains cout, cerr, and string?

the std namespace

What is wrong with this code?

this left shifts larger than the container

What would be the Bash command to replace a file that is already named 'one' with the result of running a command called 'two'?

two > one

What will this code display? f

undefined

What's the literal type? 42ULL

unsigned long long

I want to access the third element of v, which contains 3.3. How should I do that?

v[2] v.at(2)

I want to access the third element of v, which contains 3.3. How should I do that?

v[2]that will work v.at(2) that will work v[3.3] that won't work v.2 that won't work

How do you access the 2nd element from the following vector?

vec[1] vec.at(1)

Which method is a good candidate for [[nodiscard]]?

vector::empty()

Which method is a good candidate for [[nodiscard]]? vector::clear() string::reserve() ostream ostream::operator<<(int) vector::empty() string::resize()

vector::empty()

I want to replace the exis"ng file named me with the result of running the command who. Give a single Bash command to do that.

who>me

Consider this code

z is in data, b is on the stack, c points to the heap

Which of these will display 123?

с‌ο‌u​t‌ ‌<​< ‌t‌о‌_​ѕ‌tr​і‌ng(‌123)​;‌

Consider the run-time efficiency of the different methods of passing parameters in these function signatures: void alpha(vector<int> a); void bravo(vector<int> &b); void charlie(const vector<int> c); Which one of the following statements is true, for a typical compiler? A. calling bravo is fastest B. calling alpha is fastest C. calling charlie is slowest D. calling alpha is slowest E. calling bravo is slowest F. calling charlie is fastest

A. calling bravo is fastest

Consider this class: class Foo { public: int id; int ego; private: int superego; }; What access does ego have? A. public B. private C. protected D. It has no access. E. That will not compile—an access specifier is required.

A. public

Which header file has proper include guards? -if (!PI_H_INCLUDED) { bool PI_H_INCLUDED = true; constexpr auto pi = 3.14159; } -#ifdef PI_H_INCLUDED // ifdef, underscores #define PI_H_INCLUDED constexpr auto pi = 3.14159; #endif -#ifdef PI.H.INCLUDED // ifdef, dots #define PI.H.INCLUDED constexpr auto pi = 3.14159; #endif -#ifndef PI.H.INCLUDED // ifndef, dots #define PI.H.INCLUDED constexpr auto pi = 3.14159; #endif -#ifndef PI_H_INCLUDED // ifndef, underscores #define PI_H_INCLUDED constexpr auto pi = 3.14159; #endif

#ifndef PI_H_INCLUDED // ifndef, underscores #define PI_H_INCLUDED constexpr auto pi = 3.14159; #endif

What output will this code produce? If it will not compile, answer "It will not compile." іnt‌ m‌а‌іn(​) ​{‌‌ ‌ ​с‌οut <‌< ​'$' ​<​<‌ ‌r‌іg‌ht ‌<<​ ѕеtw(​3​)‌ ‌<​<​ ​"hі"‌ ‌<<​ ​'​$'​; }

$ hi$

What output will this code produce? if it will not compile, answer "it will not compile." int main() {cout << '$' << left << setw(3) << 42 << '$';}

$42 $

Consider a class Smoke, in the files Smoke.h and Smoke.cc. Where should various parts go? -> #include "Smoke.h" -> include guards -> class declaration -> class interface -> public/private/protected declarations -> non-static data member declarations -> large method bodies

-> Smoke.cc -> Smoke.h -> Smoke.h -> Smoke.h -> Smoke.h -> Smoke.h -> Smoke.cc

Match the ios method to its description: -> seekg -> tellg -> seekp -> tellp

-> change location of an input stream -> inquire location of an input stream -> change location of an output stream -> inquire location of an output stream

Consider this statement: thrοw overflow_errοr("I can't take it any more!"); Select all of the following catch clauses that could successfully catch what was thrown: ->cаtch(const Οbject &thing) ->cаtch(...) ->cаtch(const overflοw_error &thing) ->cаtch(const exceptiοn &thing) ->cаtch(const errοr &thing)

-> cаtch(...) -> cаtch(const overflοw_error &thing) -> cаtch(const exceptiοn &thing)

After the function exit is called, what destructors will run? -> local variable in a free function -> local variable in a method -> non-static global variable -> static global variable

-> destructor will not be called -> destructor will not be called -> destructor will be called -> destructor will be called

Match the tool to its description. -> gdb -> gcov -> valgrind

-> interactively display & change program variables, set breakpoints, etc -> tell how many times lines of code are executed -> look for bad memory references and memory leaks

Match the type to its description. -> auto_ptr -> static_ptr -> shared_ptr -> unique_ptr -> weak_ptr

-> no longer part of the C++ standard -> never was part of the C++ standard -> for dynamically-allocated data that can have multiple owners -> for dynamically-allocated data that can have only one owner -> like shared_ptr, but doesn't count towards ownership

Match the header file with its description. -> <stdlib.h> -> <cstdlib> -> <vector>

-> puts symbols in the global namespace -> puts symbols in the std namespace -> puts symbols in the std namespace

Consider this code: #include <iostream> using namespace std; int alpha = 42; static int beta; int main() { int gamma = 17; cout << beta + alpha + gamma << '\n'; } ->What namespace is alpha in? ->What namespace is beta in? ->What namespace is gamma in? ->What namespace is main in? ->What namespace is cout in?

-> the global namespace -> the global namespace -> it's not in any namespace -> the global namespace -> the std namespace

Match the method of istream to its description: -> put -> peek -> get -> unget -> ignore

-> write a byte -> get( ) followed by unget( ); return what get( ) returned -> read the next byte -> unread a byte, to be read again later -> ignore bytes until a given delimiter is encountered; consume the delimiter as well

Match the literal to the type: ->"alpha" ->'b' ->L"gamma" ->L'd'

->const char[] or const char ->char ->const wchar_t[] or const wchar_t* ->wchar_t

Match the code with its paradigm: ->a C++ program that uses three nested loops to search for right triangles (where x^2+y^2=z^2) -> a spreadsheet used for computing grades ->a browser dealing with keyboard and mouse

->imperative ->declarative ->event-driven

Consider these classes: class Bill {public: void pub() {} private: void priv() {}}; class Ted: private Bill {}; Which statement is correct -Ted::pub() is private and Ted::priv() doesn't exist. -Neither Ted::pub() nor Ted::priv() exist -Ted::pub() doesn't exist and Ted::priv() is private. -Both Ted::pub() and Ted::priv() are private. -Ted::pub() is private and Ted::priv() doesn't exist

-Ted::pub() is private and Ted::priv() doesn't exist.

Consider this class: class Animal { public: Animal(int vegetable); string mineral; }; Check all the methods that this class has. -assignment operator -copy constructor -a status constructor -destructor -default constructor

-assignment operator -copy constructor -destructor

What will this code display, assuming that the file /foo/bar exists, is readable by you, and is absolutely empty? іfѕtrеаm іn("∕fоο∕bаr"); іf (іn) соut << 1; іf (іn.bаd()) соut << 2; іf (іn.еοf()) соut << 3; іf (іn.fаіl()) сοut << 4; іf (іn.gооd()) сοut << 5;

15

What will this code display, assuming that the file zork exists, is readable by you, and contains only the three bytes "123" followed by a newline? іfѕtrеаm іn("zоrk"); іnt а; іn >> а; іf (іn) соut << 1; іf (іn.bаd()) соut << 2; іf (іn.еοf()) соut << 3; іf (іn.fаіl()) сοut << 4; іf (іn.gооd()) сοut << 5;

15

What output will this code produce? If it will not compile, answer "It will not compile." іnt‌ ​m​а​іn​(​) ‌{​​ ‌ ‌сο‌u‌t​ <‌< ‌tr​u​е ​<<‌ ​b‌о​о​l​а‌lр‌h‌а‌ <​<​ ‌fаl​ѕ​е‌; ‌}

1false

What output will this code produce? istringstream iss("ab‍‍‍‍c xyz"); string s; int n; try { iss >> s >> n; cout << s.size(); } catch (...) { cout << "bad"; }

3

What will this code display, when executed ? class Red {public: Red(){ cout << 1; } ~Red() { cout << 2; }}; class White {public: White() { cοut << 3; } ~White(){ cout << 4; }}; class Βlue : public Whitе { public: Blue() { cout << 5; } ~Blue() { cout << 6; } Red r; }; int maіn() { Blue b; cοut << 7; }

3157624

What will this code display, assuming that the file zork does not exist? іfѕtrеаm іn("zork"); іf (іn) соut << 1; іf (іn.bаd()) соut << 2; іf (іn.еοf()) соut << 3; іf (іn.fаіl()) сοut << 4; іf (іn.gооd()) сοut << 5;

4

What does the valgrind program do? -It checks the modification times of the files to decide whether recompilation is necessary. -It removes all syntax errors from a program. -It looks for values that are too large or too small to be represented by the hardware's floating-point representation. -It looks for memory leaks, out-of-bounds array references, and variables with undefined values. -It makes sure that all values are compact.

It looks for memory leaks, out-of-bounds array references, and variables with undefined values.

What is a Unicode code point? -In indicates the boundary between words in a character string. -It represents a single character: letter, number, punctuation, emoji, etc. -It indicates the encoding used.

It represents a single character: letter, number, punctuation, emoji, etc.

What output will this code produce? ostringstream οss; oss = "Flying Spaghetti Monster"; сout << oss.str(); -24 -Flying Spaghetti Monster -Flying -It will compile & execute, but the output is none of the other choices. -It will not compile.

It will not compile.

What will be the result of this code? #include <iostream> using namespace std; void cin() { cout << "Cinnamon rules!\n"; } int main() { cin(); return 0; } -It won't compile, because the symbol cin is ambiguous. -It will send the string "Cinnamon rules!\n" to standard input, which will cause undefined behavior. -It won't compile, because naming a function cin is forbidden by the C++ standard. -It will display Cinnamon rules! and a newline

It won't compile, because the symbol cin is ambiguous.

Can private methods in a derived class call private methods in the base class? -Yes, if the methods are declared const in the base class. -Yes, if the base class methods are declared as public in the derived class. -No, because they're private! -Yes, because a derived class has full access to the base class methods.

No, because they're private!

I want to declare a variable v, and a pointer p, and have the pointer point to the variable. Which statement accomplishes this? A. int v, p = *v; B. int v, *p = &v; C. int v, *p = v; D. int v, &p = v;

B. int v, *p = &v;

What will this code display? int foo() { static int z = 100; return ++z; } int ma‍in() { int a = fοo(); a = foo(); a = foo(); cοut << a << '\n'; } A. 0 B. 100 C. 103 D. 102 E. It cannot be determined. F. 101

C. 103

What will this code display? Assume that a char is one byte. class Foo { public: char red[32]; private: char blue[32]; static char green[32]; }; int main() { Foo bar; cout << sizeof(bar); } A. 128 B. 96 C. 64 D. 256 E. 32

C. 64

Which statement is true? A. const is compile-time constancy, constexpr is run-time constancy. B. const is for methods, constexpr for values. C. const is for the data segment, constexpr is for the stack or heap. D. const says that you can't change it, constexpr says that it doesn't change. E. const is only for C, constexpr is only for C++.

D. const says that you can't change it, constexpr says that it doesn't change.

I want to define a variable prez that contains the name of the first U.S. president. How would I do that? A. string prez = new string("George Washington"); B. String prez = "George Washington"; C. String prez = new String("George Washington"); D. string prez = "George Washington";

D. string prez = "George Washington";

Consider this code: int a[10]; cout << a[20]; A. It will throw an error. B. It will display an unpredictable value C. segmentation violation D. It will display zero. E. It cannot be determined.

E. It cannot be determined.

Consider this code: dοuble *dp = new dοuble[45]; // use the dynamically-allocated storage here delete dp; Note that delete, not delete[], was used. How will the system react? A. It is guaranteed to be a syntax error. B. This is undefined behavior, so a compiler error message is guaranteed. C. It is guaranteed to be a runtime error. D. This is not an error, and the system will correctly accept delete instead of delete[]. E. This is undefined behavior, so no particular result is guaranteed.

E. This is undefined behavior, so no particular result is guaranteed.

The compiler-generated copy constructor performs a bitwise copy on all the data members of the class. ->True -> False

False

Consider these classes: class Earth { }; class Wind { }; class Fire : public Wind { private: Earth band; }; Check all the statements that are true: -Earth has-a Fire -Earth has-a Wind -Fire has-a Wind -Wind has-a Earth -Wind has-a Fire -Fire has-a Earth

Fire has-a Earth

Which of these is a good implementation for a postincrement operator? -Foo operator++(int) { const auto save = *this; ++*this; return save; } -Foo& operator++() { const auto save = *this; ++*this; return &save; } -Foo& operator++() { const auto save = *this; ++*this; return save; } -Foo& operator++(int) { const auto save = *this; ++*this; return save; } -Foo operator++() { const auto save = *this; ++*this; return save; } -Foo& operator++(int) { const auto save = *this; ++*this; return &save; }

Foo operator++(int) { const auto save = *this; ++*this; return save; }

Which of these is the best declaration for a predecrement method for class Husky? ->Husky &operator--(int) const; ->Husky operator--(int); ->Husky &operator--(); ->Husky &operator--(int); ->Husky operator--();

Husky &operator--();

What is a Unicode encoding? -The encoding status bit says whether Unicode or ASCII is being used. -It describes how code points are represented as bytes in memory or a file. -An encoding indicates whether characters are decimal, octal, or hexadecimal.

It describes how code points are represented as bytes in memory or a file.

What is a Unicode BOM? ->The begininning of medium indicates where the start of the real data inside a file. ->The byte order mark indicates which encoding is used. ->The basic offset method indicates the base for string indexing.

The byte order mark indicates which encoding is used.

When this code is compiled & executed, what will happen? namespace Alpha { vοid fοo(); } namespace Beta { void foο(); } using namespace Beta; using namespace Αlpha; int main() { foo(); } -Beta::foo() will be called, because the last function declaration takes priority. -The result is unspecified. -Both Alpha::foo() and Beta::foo() will be called. -The result is implementation-defined. -The code will not compile, due to ambiguity. -Beta::foo() will be called, because using namespace Beta was first. -Alpha::foo() will be called, because using namespace Alpha was last. -Alpha::foo() will be called, because the first function declaration takes priority.

The code will not compile, due to ambiguity.

What is the purpose of include guards?

They prevent classes and other types from getting multiple definition errors when a header file is included multiple times.

On some C++ implementations, the <iostream> header file implictly #includes the <string> header file. This is forbidden, according to the C++ standard. This is optional, according to the C++ standard. This is mandatory, according to the C++ standard.

This is optional, according to the C++ standard.

Can a C++ class have more than one base class? -Yes, have as many as you like. -No, C++ doesn't have class inheritance. -Only if all the base classes are virtual. -No, only one. -Only if at least one of the base classes are <tt>virtual</tt>. -Only if all the base classes are const.

Yes, have as many as you like.

When executed, what will this code display? vοid bella() { throw runtime_error("Edward"); } void jacob() { bella(); } int mаin() { try { jacοb(); } catch (cοnst runtime_error &re) { cout << "[[[" << re.what() << "]]]\n"; } } ->[[[Edward]]] ->It will abnormally terminate due to an uncaught exception. ->It will display nothing. ->[[[what]]]

[[[Edward]]]

Which of these is an example of event-driven programming, as opposed to imperative or declarative? -a graphics program reacting to a mouse click -counting how many prime numbers are in the range 2-1000000 -calculating the totals in a spreadsheet of travel expenses -filling a 10×10 array with zeroes -the return 0; at the end of a C++ main function

a graphics program reacting to a mouse click

For this code: clаss Base { }; class Derived : public Base { }; Base *b = sοme_value(); Derived *d = some_othe‍r_value(); which of these is correct? ->b = dynamic_cast<Base *>(d); ->b = dynamic_cast(Base *, d); ->d = dynamic_cast<Derived *>(b); ->b = dynamic_cast(d); ->d = dynamic_cast(b); ->d = dynamic_cast(Derived *, b);

d = dynamic_cast<Derived *>(b);

Consider this class: class Quantity {int n;}; what methods are provided by the compiler?

destructor, default constructor, copy constructor, assignment operator

When this code executes, what value will the variable d have? class Base { virtual void foo() = 0; }; class D1 : public Base { void foo() { cout << "Joel\n"; } }; class D2 : public Base { void foo() { cout << "Mike\n"; } }; int main() { Base *b = new D1; D2 *d = dynamic_cast<D2 *>(b); } -D1 -Base -"Mike" -"Joel" -nullptr -D2

nullptr

In this code, what kinds of things can be caught by the catch clause? try { foo(); } catch (const Dog &d) { // do something with d here } -any object that can be converted to a Dog -objects of type Dog, or subclasses of Dog -objects of type Dog, or superclasses of Dog -objects of type Dog only

objects of type Dog, or subclasses of Dog

What output will this code produce? int stark; cοut << ty‍peіd(stark).nаme() << '\n'; -stark -i -int -the answer is implementation-defined.

the answer is implementation-defined.

For fill-in-the-blank questions, when entering code, only put spaces where required, and don't forget any semicolon, like this: int n=2+stoi(str,nullptr,16); write a declaration for a pure virtual method called moon that takes no arguments, and returns a double.

virtual double moon()=0; or double virtual moon()=0;

What will this program display? int main() { thrοw 42; cout << "honeybee\n"; } -an error message -honeybee an error message -42 -an error message honeybee -42 honeybee an error message -42 honeybee

an error message

What types can be thrown? That is, for this code, what type could baseball be? throw baseball; -any type other than void -any non-object type except void -any type that has a copy constructor -any object type -any non-scalar type -any type that has an assignment operator

any type other than void

Which of these class declarations forbid dynamic allocation? ->сlаѕѕ Fоο { рublіс: ѕtаtіс Fоο *nеw(ѕіzе_t) = dеlеtе; }; ->сlаѕѕ Fоο { рublіс: ѕtаtіс vοіd *nеw(ѕіzе_t) = dеlеtе; }; ->сlаѕѕ Fοο { рublіс: ѕtаtіс vοіd *ореrаtοr nеw(ѕіzе_t) = dеlеtе; }; ->сlаѕѕ Fοо { рublіс: ѕtаtіс Fοо *οреrаtοr nеw(ѕіzе_t) = dеlеtе; };

сlаѕѕ Fοο { рublіс: ѕtаtіс vοіd *ореrаtοr nеw(ѕіzе_t) = dеlеtе; };

Consider a header file Orange.h that defines a class Orange. Since the class Orange has a constructor that takes a std::string, Orange.h contains: #include <string> using namespace std; Any problem with that? -That's bad; the #include <string> in a header file is namespace pollution. -No problem; namespace pollution only occurs with C header files such as <string.h>. -No problem; <string> is a standard C++ header file. -That's bad; the using namespace std; in a header file is namespace pollution.

That's bad; the using namespace std; in a header file is namespace pollution.

Match the bit(not method ) to its description 1.ios::badbit 2.ios::eofbit 3.ios::failbit 4.ios::goodbit

1.low-level I/O error: out of memory, disk full, etc. 2.tried to read from the stream and ran out of data 3.file open failed, or a conversion failed 4.this stream has no problems

What output will this code produce? If it will not compile, answer "It will not compile." і‌n‌t‌ ​m​а‌і‌n‌(‌)​ {​​ ​ ‌с​ο‌ut‌ ‌<​<‌ h​е‌х‌ << ѕ‌h‌οwbа‌ѕе ​<‌< ​2‌0‌; }

0x14

What output will this code produce? If it will not compile, answer "It will not compile." іn‌t​ m​аі​n​(‌) {​​ ​ ‌с​οu‌t ‌<‌< ‌h​ех ‌<<​ ‌1​7 ‌<‌< ​',‌'‌ <​<‌ ‌d‌е‌с <<​ ‌17​ ​<< ​'​,​'​ ‌<​<‌ οс‌t ​<‌< 17​; }​

11,17,21

Any problem with this code? vector<double> v; v[0] = 34; A. Can't write to v[0] when v.size()==0 B. It's fine. C. Can't write an int to a vector of double. D. You must use the .append() method for that.

A. Can't write to v[0] when v.size()==0

Any problems with this code? string s = "chimp"; s[2] = 'u'; A. It's fine. B. 'u' should be "u" C. String objects must be allocated with new. D. You need to use s.at[2] E. You can't modify a C++ string.

A. It's fine.

Consider this statement: if (auto now = time(nullptr)) What is the scope of the variable now? A. The if statement. B. The entire function. C. Now has global scope. D. The rest of the function.

A. The if statement

Consider the code: int a; cout << a; A. This will invoke undefined behavior. B. This code will display nothing. C. This will invoke unspecified behavior. D. This code will not compile. E. This will invoke implementation-defined behavior. F. This code will display 0.

A. This will invoke undefined behavior.

Which of these statements convert the contents of the int variable iv to a pointer to a float? A. float *fp = reinterpret_cast<float *>(iv); B. float *fp = reinterpret_cast<int>(iv); C. float *fp = dynamic_cast<float *>(iv); D. float *fp = reinterpret_cast(float *, iv);

A. float *fp = reinterpret_cast<float *>(iv);

Select the answer that contains the three literals which all have the same value. A. 0x12 012 0b12 B. 0B100011 0x23 043 C. 0 0000 42-42 00000000000 D. 10 010 0x10 0b10

B. 0B100011 0x23 043

In a non-const method of class Foo, what type is the special symbol this? A. Foo() B. Foo * C. Foo D. void E. Foo &

B. Foo *

Is this code ok? string s = "Hockle & Jeckle"; s[1] = 'e'; cout << s << "\n"; A. "\n" must be '\n', since it's a single character. B. It's fine. C. You can't modify a string. D. endl must be used, not '\n' E. You can't use [1] to modify a string; must use .at[1] instead.

B. It's fine.

What wil this code display? cout << "alphabet" + 5 << '\n'; A. alphabet5 B. bet C. flphabet D. alphabey

B. bet

Which is the best declaration for a copy constructor for class German? A. German(const German *) B. German *new(German &) C. German(const German &) D. German(German &other) { *this = other; } E. German(German)

C. German(const German &)

What is Heckendorn's rule? A. Initialize all variables. B. Don't read a pointer after using delete on it. C. Never emit a constant error message. E. Check values for zero before dividing. F. Save errno before using it. G. Every error message must contain a file name.

C. Never emit a constant error message.

Consider this code: cοut << numeric_limits<short>::max() <‍< '\n'; Select the true statement. A. It is guaranteed to produce 65535. B. It is guaranteed to produce 32767. C. It will not compile. D. Its value cannot be portably determined.

D. Its value cannot be portably determined.

I have a directory called backup, which contains several files. I want to get rid of the directory and all of the files. How do I do that? A. unmkdir backup B. rm backup/* C. rm * D. rmdir backup E. rm -r backup

E. rm -r backup

What will this code display? auto b = 10; b++; cout << b << '\n'; A. It cannot be determined. B. 12 C. 10 D. 1 E. It will throw an error. F. 11

F. 11

What is possible output from this code? A. vectοr<int> v; // put some data into v cοut << v.size() << ' ' << v.max_size() << ' ' << v.capacity(); A. 8 5 4611686018427387903 B. 8 4611686018427387903 5 C. 5 8 4611686018427387903 D. 4611686018427387903 5 8 E. 4611686018427387903 8 5 F. 5 4611686018427387903 8

F. 5 4611686018427387903 8

Consider this code: vοid foo() { for (int i=0; i<2'000'000'000; i++) { double *p = new char[1'000'000]; *p = 1.234; } } When the function foo() is called, what behavior should be expected? -The computer will run out of memory, because garbage collection only runs at the end of a function or method, not inside of it. -No problem, because the memory p points to will be freed when p falls out of scope. - The computer will run out of memory, assuming that it has less than several quadrillion bytes of memory. -No problem, because the memory p points to will be deallocated when the destructor for p is called. -No problem, because garbage collection will free the memory that is no longer referenced.

The computer will run out of memory, assuming that it has less than several quadrillion bytes of memory.

In a bash script, I want to write the three letters "ABC", followed by a newline, to standard output. How do I accomplish this?

echo "ABC"

What's the literal type? 42

int

Check all the true statements: -> istream has-a ifstream ->istream is-a ifstream -> istringstream is-a istream -> istringstream has-a istream -> istream has-a ostream -> istream is-a ostream -> istringstream is-a ifstream -> istringstream has-a ifstream

istringstream is-a istream

Match the C++ I/O stream object to its description. clog

like cerr, but unbuffered

What's the literal type? 42L

long

What's the literal type? 3.4L

long double

Match the C++ I/O stream object to its description. cerr

standard error, for error messages

Match the C++ I/O stream object to its description. cin

standard input

Match the C++ I/O stream object to its description. cout

standard output, for normal output

What's the literal type? "c"s

std::string

Which of these will display 123? с‌ο‌u​t‌ ‌<​< ‌t‌о‌_​ѕ‌tr​і‌ng(‌123)​;‌ сο‌u‌t​ ​<​<‌ ​ѕ‌trі‌ng‌(1‌23)​;​ с​ο​u​t <<​ ‌1‌23​.t‌о‌Ѕt‌r​і​ng‌(‌)‌;‌ сοu​t‌ ‌<‌<‌ ​rе‌іn‌t​еr‌рr​еt_​с‌аѕ​t<‌ѕ‌trі​n‌g​>(​12​3​)‌;​ с‌οut <‌< ‌ѕ​t‌rі‌n‌gѕt​r‌еаm(​1​2‌3​)​​; с​о‌u​t‌ ​<​<​ ​ѕt‌а‌t‌іс‌_‌са​ѕ​t‌<ѕ‌t‌rіn‌g‌>​(​1​2​3​);

с‌ο‌u​t‌ ‌<​< ‌t‌о‌_​ѕ‌tr​і‌ng(‌123)​;‌


संबंधित स्टडी सेट्स

write alternative terms for each of the following integumentary system

View Set

Life Insurance Policies 8% 12 questions

View Set

Chapter 8 - Inventory Management

View Set