Concepts Review Ch 4-8, 10 Flashcards
(84 cards)
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