Exam 1 Flashcards
Who created c++ and when?
1979: Bjarne Stroustrup began work on “c with classes.” Renamed to c++ in 1983. standardized by ISO in 1998.
What is the difference between g++ and c++?
g++ is the compiler, c++ is the language
true or false: all c programs are valid c++ programs, but not the other way around.
true
true or false: main is a method
false. main is a function
what is a method?
a function inside of a class
what do you need in order to access IO facilities?
include <iostream></iostream>
what do a main function’s return values mean?
0 means success
>0 means failure
<0 means something weird happened
true or false: variable size is standard across implementations
false. size is determined by implementation
what does the const quantifier do?
it makes it so you cannot change a variable
what does the constexpr quantifier do?
it is a compile-time const
what does the static quantifier do?
it means the variable has a longer than function lifetime, but makes it private if it’s a global variable.
true or false: you must initialize variables declared as auto
true
what is cin?
standard input
what is cout?
standard output
what is cerr?
standard error
what operator is used for output with cout?
the insertion operator: «
what does cout «_space;endl do?
it flushes terminal output
what operator is used for input with cin?
the extraction operator:»_space;
how do you read an entire line from a file?
use getline. params are file name & what you will call the line
true or false: you can read a string with»_space;
True. this will read a whitespace delimited string
how do you read a raw char?
use get(). you can also use»_space; to read a whitespace delimited char
what does unget() do?
it will back up by one char
what does peek() do?
it will get and unget a char to peek at it
how do you get the stream state?
test the state by evaluating the string as a bool, since cin»_space; n returns a reference to n
what does eof do?
it tells us if the previous read hit the end of the file
what do you need to do to use vectors?
include <vector></vector>
what is a vector?
a stretchy array. no fixed size
how do you declare a vector?
vector<int> v; or
vector<int> v(10);</int></int>
what does v.size() do?
v is a vector
returns the current length as a size_t
what does v.push_back() do?
v is a vector.
adds an element to the end of a vector
what does v.pop_back() do?
v is a vector
removes an element from the end
what does v[i] or v.at(i) do?
v is a vector
indexing
when does a vector grow in size?
when given a size_t ctor arg, when using push_back(), or when using resize()
what do you need to do to use c++ strings?
include <string></string>
what are literals?
constants.
what does a c++ string literal look like?
“foobar”s
what is string pasting?
string pasting is done by the compiler. two adjacent string literals are merged into one at compile time.
What does a raw string look like?
a raw string starts with R”( and ends with )”
how do you compare c++ strings?
convert them to c strings and use strcmp()
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.