If you have a string named petName that holds the value of "goldie," what does petName.length() equal?
6
Which of the following is not a logical operator?
(a) &&
(b) !
(c) <=
(d) ||
c - c is a relational operator
Write a condition to determine if a variable num stores a number between 0 and 4, inclusive.
if (num >= 0 && num <= 4)
Which of the following is not true about functions in C++?
A) A function can return at most one value.
B) A function must always return a value.
C) Functions can take zero or more parameters.
D) Functions can call other functions.
B
What is the difference between arithmetic and relational operators?
Arithmetic assign/change a value, relational compare values
If you have a string named petName that holds the value of "goldie," what does petName[3] equal?
'd'
What is the missing value in the truth table?
T
int n = -5;
if (n){
cout << "True branch"<< endl;}
else{
cout << "False branch" << endl;}
True branch
int square(int n) {
return n * n;
}
int main() {
cout << square(3 + 1);
}
16
What's the difference between pass by value and pass by reference
Pass by reference actually updates the variable; pass by value only passes the current value of the variable.
cout << "happy" + 5 << endl;
compilation error
What are the integer representations of Boolean Values
0 and 1
T/F: When writing switch statements in c++ you must include a default case, otherwise your switch statement is not valid.
False
What does the keyword void mean when used as a function return type?
The function does not return a value (most used for printing things).
Why are "break"s important when writing switch statements?
So the code doesn't "fall through" to the next case.
If you have a string named petName that holds the value of "goldie," what does petName.substr[0,3] equal?
"gol"
(5 > 2) && (10 == 5)
int x = 4;
if (x = 0){
cout << "A"; }
else if (x > 0) {
cout << "B"; }
else {
cout << "C";}
C
int mystery(int a, int b) {
if (a > b){
return a - b;}
else {
return b - a;}
}
int main() {
cout << mystery(10, 4) << endl;
cout << mystery(4, 10) << endl;
}
6
6
What's the difference between a parameter and an argument in a function.
Arguments are the values that are actually passed into the function, parameters are the placeholders or variables defined in the function
If you have a string named petName that holds the value of "goldie," what does petName.substr[3,2] equal?
"di"
int x = 7;
int y = 14;
bool result = (x * 2 == y) || (y / x > 2);
True
int num = 13;
switch (num % 4) {
case 0: cout << "Divisible by 4"; break;
case 1: cout << "Remainder 1";
case 2: cout << "Remainder 2"; break;
default: cout << "Other";
}
Remainder1Remainder2
void update(int &x, int &y) {
x = x + 5;
y = y * 2;}
int main() {
int a = 3,
b = 4;
cout << "Before: " << a << " " << b << endl;
update(a, b);
cout << "After: " << a << " " << b << endl; return 0;
}
Before: 3 4
After: 8 8
What happens if you forget to return a value from a non-void function in C++?
Compile time error (or sometimes other unexpected behavior)