Exam 1 Flashcards

1
Q

Who created c++ and when?

A

1979: Bjarne Stroustrup began work on “c with classes.” Renamed to c++ in 1983. standardized by ISO in 1998.

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

What is the difference between g++ and c++?

A

g++ is the compiler, c++ is the language

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

true or false: all c programs are valid c++ programs, but not the other way around.

A

true

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

true or false: main is a method

A

false. main is a function

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

what is a method?

A

a function inside of a class

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

what do you need in order to access IO facilities?

A

include <iostream></iostream>

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

what do a main function’s return values mean?

A

0 means success
>0 means failure
<0 means something weird happened

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

true or false: variable size is standard across implementations

A

false. size is determined by implementation

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

what does the const quantifier do?

A

it makes it so you cannot change a variable

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

what does the constexpr quantifier do?

A

it is a compile-time const

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

what does the static quantifier do?

A

it means the variable has a longer than function lifetime, but makes it private if it’s a global variable.

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

true or false: you must initialize variables declared as auto

A

true

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

what is cin?

A

standard input

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

what is cout?

A

standard output

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

what is cerr?

A

standard error

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

what operator is used for output with cout?

A

the insertion operator: «

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

what does cout &laquo_space;endl do?

A

it flushes terminal output

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

what operator is used for input with cin?

A

the extraction operator:&raquo_space;

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

how do you read an entire line from a file?

A

use getline. params are file name & what you will call the line

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

true or false: you can read a string with&raquo_space;

A

True. this will read a whitespace delimited string

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

how do you read a raw char?

A

use get(). you can also use&raquo_space; to read a whitespace delimited char

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

what does unget() do?

A

it will back up by one char

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

what does peek() do?

A

it will get and unget a char to peek at it

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

how do you get the stream state?

A

test the state by evaluating the string as a bool, since cin&raquo_space; n returns a reference to n

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
what does eof do?
it tells us if the previous read hit the end of the file
26
what do you need to do to use vectors?
#include
27
what is a vector?
a stretchy array. no fixed size
28
how do you declare a vector?
vector v; or vector v(10);
29
what does v.size() do? v is a vector
returns the current length as a size_t
30
what does v.push_back() do? v is a vector.
adds an element to the end of a vector
31
what does v.pop_back() do? v is a vector
removes an element from the end
32
what does v[i] or v.at(i) do? v is a vector
indexing
33
when does a vector grow in size?
when given a size_t ctor arg, when using push_back(), or when using resize()
34
what do you need to do to use c++ strings?
#include
35
what are literals?
constants.
36
what does a c++ string literal look like?
"foobar"s
37
what is string pasting?
string pasting is done by the compiler. two adjacent string literals are merged into one at compile time.
38
What does a raw string look like?
a raw string starts with R"( and ends with )"
39
how do you compare c++ strings?
convert them to c strings and use strcmp()
40
true or false: if a variable is const, it is read-only
False. it doesn't mean that it's read-only, it just means that YOU can't change it.
41
what is a method?
a method is a function inside of a class
42
true or false: in c++ functions, trailing arguments can have default values
true
43
true or false: in c++ function overloading, types & return value across multiple functions must be the same.
false
44
is c++ a pass by value or pass by reference language?
pass by value.
45
what does pass by value mean?
copies are made of the arguments, and the copies are passed to a function or method. if we want to change the argument, we must instead pass by reference.
46
how can you pass a read-only reference?
use const
47
true or false: arrays are always passed by reference
true
48
how do you dynamically allocate memory in c++?
new and delete
49
what happens if you call new and delete incorrectly, or you call the wrong one?
undefined behavior
50
what happens if you dont call delete?
memory leak
51
what happens if you call delete more than once?
undefined behavior
52
what is a dangling pointer?
a pointer that has been deleted. the data still exists, but it is not yours.
53
true or false: accessing the value of a deleted pointer is undefined behavior
true
54
what does the ampersand mean when used in an expression in c++?
it means the "address of"
55
what does an ampersand mean when used in a definition in c++?
it means "i am a reference"
56
what is a null pointer?
a pointer that is not intended to point to anything useful
57
true or false: a reference is impermanent and can be changed.
false. a reference is permanent
58
which is faster, call by reference or call by value?
call by reference
59
what is .size()
how many elements the container currently contains
60
what is .capacity()
how many elements are allocated to the container
61
what is .max_size()
biggest possible .size() on this computer
62
what does .reserve() do?
changes the allocated size
63
what does .resize() do?
changes the size. if it had more than n elements, we lose some. if it had less, we gain some.
64
true or false: sizeof(), size(), and .size() are the same
false. sizeof() is a compile-time function that returns the size of an object in bytes .size() is a container method that returns the number of elements size() is a free function that is identical to .size() but also works on C arrays
65
what is heckendorn's rule?
never emit a constant error message.
66
What information should be included in an error message?
program name file name operation attempted error code via errno text error description strerror()
67
what is variable scope?
visibility; which code can access the variable?
68
what is variable lifetime?
duration; when the variable is created and destroyed
69
what does it mean to make a global variable static?
it changes the scope of the global variable to be only the current file
70
what does it mean to make a local variable static?
it increases the lifetime of a local variable
71
what do you need to do in order to use numeric_limits?
#include
72
how do classes and structs differ?
methods, data, and inheritance are by default private for a class and public for a struct
73
what do attributes do?
they add extra information to a variable, function, type, or statement
74
what does the [[deprecated]] attribute mean?
it means support will be withdrawn soon- stop using it
75
what does the [[fallthrough]] attribute mean?
indicates that a switch statement "falling through" to later cases is ok/intentional
76
what does the [[maybe_unused]] attribute mean?
it tells the compiler not to complain that a type, variable, argument, or function isn't being used
77
what are some alternatives to using the [[maybe_unused]] attribute?
omit the name of the argument/variable if the name has mnemonic value, place it in a /* comment */
78
what does the [[nodiscard]] attribute mean?
the return value must be used
79
what does the [[noreturn]] attribute mean?
it indicates that the function does not return.
80
what do the -O flag and -O1 flag mean in g++
general optimization
81
what does the -O2 flag mean in g++?
more optimization than O and O1
82
what does the -O3 flag mean in g++?
the most optimization possible
83
what does the -flto flag mean in g++?
perform link-time optimization; tells the compiler to perform optimization between the individual .o object files
84
what does the special class variable "this" do?
it is a pointer to the current object
85
how do you make a class work for output?
define the << operator properly
86
true or false: methods must be declared and defined inside of the class
false. methods are declared in the class, but must be defined outside of the class
87
what three types of protection can class members have?
public, private, and protected
88
what does it mean for a class member to be public?
anyone can access it
89
what does it mean for a class member to be private?
nobody except other methods of this class may access them
90
what does it mean for a class member to be protected?
they can be accessed by this class and by immediately derived classes.
91
what does it mean for a class to declare something as its frend?
it allows the friend class, function, or method to access private data
92
how would you declare a class named Bar as a friend?
friend class Bar;
93
how would you declare a method named double zulu(int) const from the class Zip as a friend?
friend double Zip::zulu(int) const;
94
how would you declare a function named int alpha() as a friend?
friend int alpha();
95
true or false: class A can request friendship from class B
false. friendship is offered, not demanded
96
true or false: if class A is class B's friend, then class B is class A's friend.
false. friendship is not always symmetric
97
true or false: if class A and B are friends, and B and C are friends, then A and C are friends.
false. friendship is not transitive
98
true or false: if class A and B are friends, and class C is A's child, then B and C are friends.
false. friendship is not inherited
99
true or false: if class A is class B's child, then class A and class B are friends.
false. inheritance does not imply friendship.
100
true or false: a static class member variable has class scope
true
101
what level of protection can a class static variable have?
public, protected, or private
102
true or false: a static class variable can be called without an instance of the class.
true