1/97
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 the safest default loop condition for traversing an array of size kSize?
i < kSize.
Why is i <= kSize usually wrong for an array traversal?
It attempts to access index kSize, which is one past the last valid index.
What does partial numeric-array initialization do?
Unspecified remaining elements are initialized to zero.
Why should array sizes commonly use a named constant?
It makes the size clear and allows one-point changes.
What is the output of int a[3] = {10,20,30}; cout << a[1];?
20.
What is the output of int a[3] = {10,20,30}; cout << *(a + 2);?
30.
Why can an out-of-bounds array access be dangerous even if compilation succeeds?
C++ often does not perform runtime bounds checking, so memory can be corrupted.
How should a function print an array without modifying it?
Use a const array parameter, such as void Print(const int a[], int size).
What does an array argument look like in a function call?
Pass the array name, such as Print(a, size), not a[].
What does passing an array to a function allow the function to do?
Access the original caller-owned array.
What is the purpose of the separate size parameter for an array?
Built-in arrays do not carry their length automatically into the function.
What is the valid index range of int grid[2][3]?
Rows 0-1 and columns 0-2.
What is grid[1][2] for {{1,2,3},{4,5,6}}?
6.
What is required for binary search that is not required for linear search?
The data must be sorted.
What are the three main variables in a binary search trace?
Low, middle, and high indexes.
What should happen to the binary-search range after the target is smaller than the middle value?
Search the left half by reducing the high boundary.
What should happen after the target is larger than the middle value?
Search the right half by increasing the low boundary.
What is the basic idea of bubble sort?
Swap adjacent out-of-order values repeatedly.
What is the basic idea of selection sort?
Find the smallest remaining value and place it at the front of the unsorted portion.
What is the basic idea of insertion sort?
Insert the next value into the correct place in the sorted prefix.
What is the null character?
The character \0 that terminates a C-string.
How much storage does char s[] = "CSCE"; require?
5 characters, including \0.
Why can cout << a character array be dangerous if there is no null character?
It may continue reading past the intended array until a zero byte happens to appear.
What does cin >> word do with whitespace?
It stops at whitespace such as a space, tab, or newline.
What does int *p declare?
p as a pointer to int.
What does int **p declare?
p as a pointer to a pointer to int.
What is the difference between p and *p?
p is an address; *p is the value at that address.
What is the difference between &x and *p?
&x obtains an address; *p dereferences an address to obtain a value.
If p points to x, what does ++*p do?
It increments the value of x.
What does ++p do?
It moves p to the next address-sized element of its pointed-to type.
What does p + 1 mean for an int pointer?
The address of the next int-sized element.
Why are pointer types important?
The type determines how dereferencing and pointer arithmetic interpret memory.
What does const int *p prevent?
Changing the pointed-to int through p.
What does int *const p prevent?
Changing the address stored in p.
What does const int *const p prevent?
Changing either the address or pointed-to value through p.
Why might a function take a pointer parameter?
To access or modify caller-owned data and to support pointer-based traversal.
What does new int allocate?
One dynamic int.
What does new int[size] allocate?
A dynamic array of size ints.
What must match new[]?
delete[].
What must match new?
delete.
What is the classic memory-leak pattern p = new int; p = new int;?
The first allocation becomes unreachable before it is deleted.
What should usually happen after delete p?
p may be set to nullptr if it will remain in use, to avoid a dangling pointer.
What is a dangling pointer?
A pointer that refers to memory whose lifetime has ended.
What is a structure?
A user-defined type that groups related data members.
What is an object?
A variable or instance of a class or structure type.
What is the default access level in a struct?
public.
What is the default access level in a class?
private.
What does public mean?
Client code can directly access the member.
What does private mean?
Only the class and permitted friends can directly access the member.
What does protected mean?
The class, friends, and derived classes can directly access the member.
Why are data members often private?
To protect representation and enforce rules through member functions.
What is the difference between object.member and pointer->member?
Dot is for an object; arrow is for a pointer to an object.
What is the equivalent of ptr->member?
(*ptr).member.
What is a class definition?
The declaration of a class's name and members.
What is a class implementation?
The definitions of the class's member functions.
What is a constructor's name?
The same as the class name.
Does a constructor have a return type?
No.
When does a constructor run?
When an object is created.
What is a default constructor?
One callable without arguments.
Why is explicit useful on a one-argument constructor?
It prevents implicit conversion from the argument type to the class type.
What is a copy constructor?
A constructor that creates a new object from an existing object, commonly Class(const Class& other).
What is the difference between copying and assignment?
Copy construction creates a new object; assignment copies into an existing object.
What is a destructor's name?
~ClassName.
Can a destructor take arguments?
No.
Can a destructor be overloaded?
No.
When does delete do for a dynamic class object?
It releases memory and calls the object's destructor.
What is an accessor or get function?
A member function that returns a controlled view of data.
What is a mutator or set function?
A member function that changes data under class rules.
How is an outside-class member definition written?
ClassName::FunctionName.
What does a const member-function suffix promise?
The function will not modify the object through this.
Can a non-const member function be called on a const object?
No.
Why use a member initializer list?
To initialize members before the constructor body, especially const members and contained objects.
Why can a const data member not be assigned in the constructor body?
It must already be initialized before the body executes.
What is a friend function?
A non-member granted private/protected access by the class.
Is a friend function a member function?
No.
Is friendship automatically mutual?
No.
Is friendship automatically transitive?
No.
What does composition mean?
One class contains an object of another class; it is a has-a relationship.
What happens to a contained object when its containing object is destroyed?
The contained object's destructor participates in the containing object's destruction.
What is the this pointer?
The address of the current object in a non-static member function.
What does *this represent?
The current object itself.
Why do static member functions not have this?
They are not tied to one particular object.
What is a static data member?
One shared class-level data member rather than a separate copy per object.
Can a static function directly access ordinary non-static members?
No, because it has no this pointer.
What is operator overloading?
Defining how an operator works with a user-defined class.
How is operator overloading different from function overloading?
Operator overloading defines an operator function; function overloading uses one function name with different parameter lists.
What is the principle of least privilege?
Give code only the access it needs, often using const and private members.
Which operator accesses a member through an object?
.
Which operator accesses a member through an object pointer?
->
Which allocation requires delete[]?
new[].
Which allocation requires delete?
new.
What is the most common array-traversal off-by-one error?
Using <= instead of <.
What is the most common pointer-tracing mistake?
Confusing the pointer address with the value obtained by dereferencing.
What is the most common C-string mistake?
Forgetting that storage must include the terminating \0.
What is the most common class-access mistake?
Using dot on a pointer or arrow on a non-pointer object.
What is the most common dynamic-memory mistake?
Losing the only pointer to an allocation before releasing it.
What should you practice most if the exam follows Exam 1's pattern?
Output tracing, validity checks, state changes, and explaining why code is correct or incorrect.