Concepts Review Ch 4-8, 10 Flashcards
Precedence of relational operators:
> >= <
== !=
- True
- False
True
Using the indirection operator (*) allows you to dereference the pointer.
- True
- False
True
You can add data into an array by using the initializer method at any time.
- True
- False
False. The initializer method can only be used at the time you declare the array.
Which vector declaration is valid?
- vector exampleVector;
- vector exampleVector(10);
- vector exampleVector(10, 2);
- vector vectorOne(10, 2);
vector vectorTwo(vectorOne);
All four are valid.
What is the difference when an array holding numeric values is defined globally and when it is defined locally?
When defined globally, all of its elements are initialized to zero by default.
Local arrays, however, have no default initialization value.
To use any data type, what 2 things do you need to know?
- What values it can hold
- What operations apply to it
When an argument is passed into a parameter by _____, only a copy of the argument’s value is passed. Changes to the parameter do not affect the original argument.
value
How can you avoid dangling pointers?
By setting the pointer to NULL after you call delete on the pointer.
Which of the following are true about destructors?
- have no return type
- cannot accept arguments
- there can only be one destructor
All are true.
When would you use a for loop?
Ideal in situations where the exact number of iterations is known.
Class name and scope resolution operator (::) are an extension of the function name. When a function is defined outside the class declaration, you do not need to use the scope resolution operator.
- True
- False
False. When a function is defined outside of the class declaration, these must be present and must be located immediately before the function name in the function header.
Which pointer declaration is invalid?
- double *myDoublePointer;
- double* myDoublePointer2;
- double * myDoublePointer3;
None. They are all valid.
What is a mutator function?
A mutator function stores a value in a member variable or changes its value. Commonly known as set/setter functions because they set the value of a class variable.
What is an accessor function?
An accessor function uses the value of a class variable, but does not change it. Commonly known as get/getter functions because they just retrieve or use the value.
If the pointer is a pointer to a constant, you can use the indirection operator (*) or the structure pointer indirection operator (->) on the left side of an assignment statement.
- True
- False
False. You cannot use the * or -> operators on the left side of assignment statement.
A function cannnot send a value back to the part of the program that called the function.
- True
- False
False.
Functions may return true or false values.
- True
- False
True
When would you use a while loop?
Where you do not want the loop to iterate if the test condition is false from the beginning.
Ex: validating input that has been read and reading lists of data terminated by a sentinel value
When specifying higher dimensional arrays as parameters for functions, you must define the size of every dimension.
- True
- False
False. You must define the size of every dimension EXCEPT the first dimension.
C++ allows a set of variables to be combined together into a single unit called a structure.
- True
- False
True
You do not need to specify an initialization list when you leave out the size declarator.
- True
- False
False. If you leave out the size declarator, you must specify an initialization list.
What do you use to access individual elements of the array?
Subscripts.
How can you increase the size of a vector after it has been initially declared?
vectormyVector(10);
- You can add values to the end of the vector by calling the push_back function.
myVector.push_back(1.23); - You can increase the size by calling the resize function.
myVector.resize(20)
This eliminates the need to place a function definition before all calls to the function.
Function prototype
aka
function declarations
In an array, the name of an array variable is not a pointer.
- True
- False
False
What is the subscript of the last element in the array?
The subscript of the last element in the array is one less than the total number of elements in the array.
_________ _________ are passed to parameters automatically if no argument is provided in the function call.
Where should they be assigned?
Default Arguments
A function’s default arguments should be assigned in the earliest occurrence of the function name. This will usually be the function prototype. If a function doesn’t have a prototype, default arguments may be specified in the function header.
What are 4 differences in the way a structure is declared to the way a class is declared?
- the keyword struct is used instead of class
- structures rarely include member functions, normally declaration only declares member variables
- declarations normally do not include access specifiers public or private
- members of structure default to being public
A __________ __________ is a statement that causes a function to execute.
A __________ __________ contains the statements that make up the function.
function call
function definition
You can enter or get data from an array in any order.
- True
- False
True
What operator allows you to access members of a structure?
The dot operator.
What is the primary advantage of a vector over a 1D array?
Vectors are not fixed in size or length. You can add items to the end of the vector and the vector will automatically allocate more memory if needed to store the new item.
What do the following vector member functions do?
- vectorName.size()
- vectorName.pop_back()
- vectorName.clear()
- vectorName.size() - returns the number of elements in the vector
- vectorName.pop_back() - removes the last element of vectorName
- vectorName.clear() - Clears a vector of all its elements