1/53
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
What is an array in C++?
A fixed-size collection of values of one type stored in contiguous memory.
What is the first index of a C++ array?
0.
What are the valid indexes of an array with size n?
0 through n - 1.
What does int x[5] = {3, 7, 2}; initialize x to?
{3, 7, 2, 0, 0}.
What does int x[] = {3, 7, 2}; make the size?
3.
What happens when an array index is outside its valid range?
Undefined behavior; it may corrupt memory, appear to work, or crash.
What does the name of an array generally represent in an expression?
The address of its first element.
What does x[4] mean?
The value at index 4, equivalent to *(x + 4).
How are multidimensional arrays declared?
With multiple bracketed dimensions, such as int x[3][8].
How are multidimensional arrays initialized?
With a list of row lists, such as {{1, 2}, {3, 4}}.
Which dimensions need sizes in a multidimensional array parameter?
Every dimension except the first.
What is a C-string?
A character array terminated by the null character \0.
What is the size of char word[] = "Hello";?
6, including the terminating \0.
What does cout << word do for a C-string?
Prints characters until it reaches \0.
What is the danger of cin >> word for a character array?
Input can exceed the array's capacity and overrun its bounds.
How are one-dimensional arrays passed to functions?
Use an empty bracket parameter and pass the array name, such as void f(const int a[], int size).
Does an array parameter copy the entire array?
No. The function receives access to the caller's array.
Why use const in an array parameter?
To prevent the function from modifying the caller's array.
What is linear search?
Checking elements one at a time until the target is found or the array ends.
What condition is required for binary search?
The array must be sorted.
What does binary search do after checking the middle element?
It discards the half that cannot contain the target.
What does bubble sort do?
Repeatedly swaps adjacent out-of-order elements.
What does selection sort do?
Finds the smallest remaining element and swaps it into the next position.
What does insertion sort do?
Inserts the next element into the already-sorted portion.
What is a pointer?
A variable that stores a memory address.
What does &x produce?
The address of x.
What does *p produce?
The value stored at the address held by p.
If p points to x, what does *p = 9 do?
It changes x to 9.
What does adding 1 to a pointer do?
Moves it to the next object of its pointed-to type.
What is the relationship between a[i] and *(a + i)?
They access the same array element.
What does const int *p mean?
The pointed-to data cannot be changed through p, but p can point elsewhere.
What does int * const p mean?
p cannot point elsewhere, but the pointed-to data can change through p.
What does const int * const p mean?
Neither the pointer nor the pointed-to data can change through p.
What does new do?
Allocates memory dynamically and returns its address.
When is delete used?
To release one object allocated with new.
When is delete[] used?
To release an array allocated with new[].
What is a memory leak?
Allocated memory that is no longer reachable or released.
What is a structure?
A user-defined type containing data members.
What is the practical default-access difference between struct and class?
struct members are public by default; class members are private by default.
When is the dot operator used?
With an object, such as object.member.
When is the arrow operator used?
With a pointer to an object, such as pointer->member.
What is a constructor?
A special function with the class name, no return type, called when an object is created.
What is a default constructor?
A constructor callable with no arguments.
Why use explicit on a single-argument constructor?
To prevent unwanted implicit conversions.
What is a destructor?
A function named ~ClassName with no arguments or return type, called when an object is destroyed.
Can destructors be overloaded?
No.
What is a constant member function?
A member function declared const that cannot modify its object.
What is an accessor?
A function that returns information from an object.
What is a mutator?
A function that changes an object's data under class control.
What is a friend function?
A non-member function granted access to a class's private or protected members.
What is composition?
A has-a relationship in which one class contains an object of another class.
What is the this pointer?
A pointer to the current object inside a non-static member function.
What is operator overloading?
Giving an operator meaning for a user-defined class type.