Concepts Ch6-8, 10 Flashcards
(60 cards)
A class is a programmer-defined data type that describes what objects of the class will look like when they are created. * True * False
True
A constant pointer is a pointer whose address value is constant. The value of the object at the address cannot be changed.
- True
- False
False. While a constant pointer is a pointer whose address value is constant, the value of the object at the address CAN be changed.
int * const ptr;
A program statement outside of a class can access a private member. * True * False
False. A compiler error will result.
A vector is a data type that allows you to store and manipulate 1D data.
- True
- False
True
A float, string, structure, or a class can be referenced by an address.
- True
- False
True
Arrays are automatically passed by reference.
- True
- False
True.
Caution: if you modify the array inside the function, you are modifying the actual data and any use of the array after the function returns will see the modifications made in the array.
Array names are pointer constants.
- True
- False
True
C++ allows a set of variables to be combined together into a single unit called a structure. * True * False
True
Arrays of structures are handled the same way as arrays of objects.
- True
- False
True
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.
Constant pointers must be assigned an intial value when created.
- True
- False
True
Constant pointers to constants make the address in the pointer constant and the value of what it points to constant.
- True
- False
True
Declaring function parameters as pointers is another way to pass objects by reference.
- True
- False
True
How are member of a structure accessed?
With the dot operator.
How are structures passed by default? * by value * by reference * by constant reference
Passed by value. A copy of the entire original structure is made and passed to the function.
How can you avoid dangling pointers?
By setting the pointer to NULL after you call delete on the pointer.
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)
How should structures be passed by normally and what does it do for the function? * by value * by reference * by constant reference
Passed to functions by reference, which allows the function to access the member variables of the original structure, allowing it to change them.
If a function needs to store or change data in an object’s member variables, the object must be passed to it by value. * True * False
False. It must be passed to it by reference.
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.
If you do not need to modify the array in a function, you should not use the const keyword in the function declaration.
- True
- False
False. You should use the const keyword. This can prevent you from accidentally modifying the array values.
In an array, the name of an array variable is not a pointer.
- True
- False
False
Pointer variables never store an address.
- True
- False
False
To compare the contents of an array, what must you do?
You must compare their individual elements.