Strings
Booleans
Conditionals
Functions
Extra
100

If you have a string named petName that holds the value of "goldie," what does petName.length() equal?

6

100

Which of the following is not a logical operator?

(a) &&

(b) !

(c) <=

(d) ||

c - c is a relational operator

100

Write a condition to determine if a variable num stores a number between 0 and 4, inclusive.

if (num >= 0 && num <= 4)

100

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

100

What is the difference between arithmetic and relational operators?  

Arithmetic assign/change a value, relational compare values

200

If you have a string named petName that holds the value of "goldie," what does petName[3] equal?

'd'

200

What is the missing value in the truth table?

T

200

int n = -5;

if (n){

    cout << "True branch"<< endl;}

else{

    cout << "False branch" << endl;}


True branch

200

int square(int n) {

    return n * n;

}

int main() {

    cout << square(3 + 1);

}

16

200

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. 

300

cout << "happy" + 5 << endl;

compilation error

300

What are the integer representations of Boolean Values

0 and 1

300

T/F: When writing switch statements in c++ you must include a default case, otherwise your switch statement is not valid.

False

300

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).

300

Why are "break"s important when writing switch statements?

So the code doesn't "fall through" to the next case.

400

If you have a string named petName that holds the value of "goldie," what does petName.substr[0,3] equal?

"gol"

400

(5 > 2) && (10 == 5)

False
400

int x = 4;

if (x = 0){ 

    cout << "A"; }

else if (x > 0) {

    cout << "B"; }

else {

    cout << "C";}

C

400

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

400

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 

500

If you have a string named petName that holds the value of "goldie," what does petName.substr[3,2] equal?

"di"

500

int x = 7;

int y = 14;

bool result = (x * 2 == y) || (y / x > 2);

True

500

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

500

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


500

What happens if you forget to return a value from a non-void function in C++?

Compile time error (or sometimes other unexpected behavior)