CSCE 240 Exam 2 Secondary Study Guide

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/97

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 1:42 AM on 10/16/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

98 Terms

1
New cards

What is the safest default loop condition for traversing an array of size kSize?

i < kSize.

2
New cards

Why is i <= kSize usually wrong for an array traversal?

It attempts to access index kSize, which is one past the last valid index.

3
New cards

What does partial numeric-array initialization do?

Unspecified remaining elements are initialized to zero.

4
New cards

Why should array sizes commonly use a named constant?

It makes the size clear and allows one-point changes.

5
New cards

What is the output of int a[3] = {10,20,30}; cout << a[1];?

20.

6
New cards

What is the output of int a[3] = {10,20,30}; cout << *(a + 2);?

30.

7
New cards

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.

8
New cards

How should a function print an array without modifying it?

Use a const array parameter, such as void Print(const int a[], int size).

9
New cards

What does an array argument look like in a function call?

Pass the array name, such as Print(a, size), not a[].

10
New cards

What does passing an array to a function allow the function to do?

Access the original caller-owned array.

11
New cards

What is the purpose of the separate size parameter for an array?

Built-in arrays do not carry their length automatically into the function.

12
New cards

What is the valid index range of int grid[2][3]?

Rows 0-1 and columns 0-2.

13
New cards

What is grid[1][2] for {{1,2,3},{4,5,6}}?

6.

14
New cards

What is required for binary search that is not required for linear search?

The data must be sorted.

15
New cards

What are the three main variables in a binary search trace?

Low, middle, and high indexes.

16
New cards

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.

17
New cards

What should happen after the target is larger than the middle value?

Search the right half by increasing the low boundary.

18
New cards

What is the basic idea of bubble sort?

Swap adjacent out-of-order values repeatedly.

19
New cards

What is the basic idea of selection sort?

Find the smallest remaining value and place it at the front of the unsorted portion.

20
New cards

What is the basic idea of insertion sort?

Insert the next value into the correct place in the sorted prefix.

21
New cards

What is the null character?

The character \0 that terminates a C-string.

22
New cards

How much storage does char s[] = "CSCE"; require?

5 characters, including \0.

23
New cards

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.

24
New cards

What does cin >> word do with whitespace?

It stops at whitespace such as a space, tab, or newline.

25
New cards

What does int *p declare?

p as a pointer to int.

26
New cards

What does int **p declare?

p as a pointer to a pointer to int.

27
New cards

What is the difference between p and *p?

p is an address; *p is the value at that address.

28
New cards

What is the difference between &x and *p?

&x obtains an address; *p dereferences an address to obtain a value.

29
New cards

If p points to x, what does ++*p do?

It increments the value of x.

30
New cards

What does ++p do?

It moves p to the next address-sized element of its pointed-to type.

31
New cards

What does p + 1 mean for an int pointer?

The address of the next int-sized element.

32
New cards

Why are pointer types important?

The type determines how dereferencing and pointer arithmetic interpret memory.

33
New cards

What does const int *p prevent?

Changing the pointed-to int through p.

34
New cards

What does int *const p prevent?

Changing the address stored in p.

35
New cards

What does const int *const p prevent?

Changing either the address or pointed-to value through p.

36
New cards

Why might a function take a pointer parameter?

To access or modify caller-owned data and to support pointer-based traversal.

37
New cards

What does new int allocate?

One dynamic int.

38
New cards

What does new int[size] allocate?

A dynamic array of size ints.

39
New cards

What must match new[]?

delete[].

40
New cards

What must match new?

delete.

41
New cards

What is the classic memory-leak pattern p = new int; p = new int;?

The first allocation becomes unreachable before it is deleted.

42
New cards

What should usually happen after delete p?

p may be set to nullptr if it will remain in use, to avoid a dangling pointer.

43
New cards

What is a dangling pointer?

A pointer that refers to memory whose lifetime has ended.

44
New cards

What is a structure?

A user-defined type that groups related data members.

45
New cards

What is an object?

A variable or instance of a class or structure type.

46
New cards

What is the default access level in a struct?

public.

47
New cards

What is the default access level in a class?

private.

48
New cards

What does public mean?

Client code can directly access the member.

49
New cards

What does private mean?

Only the class and permitted friends can directly access the member.

50
New cards

What does protected mean?

The class, friends, and derived classes can directly access the member.

51
New cards

Why are data members often private?

To protect representation and enforce rules through member functions.

52
New cards

What is the difference between object.member and pointer->member?

Dot is for an object; arrow is for a pointer to an object.

53
New cards

What is the equivalent of ptr->member?

(*ptr).member.

54
New cards

What is a class definition?

The declaration of a class's name and members.

55
New cards

What is a class implementation?

The definitions of the class's member functions.

56
New cards

What is a constructor's name?

The same as the class name.

57
New cards

Does a constructor have a return type?

No.

58
New cards

When does a constructor run?

When an object is created.

59
New cards

What is a default constructor?

One callable without arguments.

60
New cards

Why is explicit useful on a one-argument constructor?

It prevents implicit conversion from the argument type to the class type.

61
New cards

What is a copy constructor?

A constructor that creates a new object from an existing object, commonly Class(const Class& other).

62
New cards

What is the difference between copying and assignment?

Copy construction creates a new object; assignment copies into an existing object.

63
New cards

What is a destructor's name?

~ClassName.

64
New cards

Can a destructor take arguments?

No.

65
New cards

Can a destructor be overloaded?

No.

66
New cards

When does delete do for a dynamic class object?

It releases memory and calls the object's destructor.

67
New cards

What is an accessor or get function?

A member function that returns a controlled view of data.

68
New cards

What is a mutator or set function?

A member function that changes data under class rules.

69
New cards

How is an outside-class member definition written?

ClassName::FunctionName.

70
New cards

What does a const member-function suffix promise?

The function will not modify the object through this.

71
New cards

Can a non-const member function be called on a const object?

No.

72
New cards

Why use a member initializer list?

To initialize members before the constructor body, especially const members and contained objects.

73
New cards

Why can a const data member not be assigned in the constructor body?

It must already be initialized before the body executes.

74
New cards

What is a friend function?

A non-member granted private/protected access by the class.

75
New cards

Is a friend function a member function?

No.

76
New cards

Is friendship automatically mutual?

No.

77
New cards

Is friendship automatically transitive?

No.

78
New cards

What does composition mean?

One class contains an object of another class; it is a has-a relationship.

79
New cards

What happens to a contained object when its containing object is destroyed?

The contained object's destructor participates in the containing object's destruction.

80
New cards

What is the this pointer?

The address of the current object in a non-static member function.

81
New cards

What does *this represent?

The current object itself.

82
New cards

Why do static member functions not have this?

They are not tied to one particular object.

83
New cards

What is a static data member?

One shared class-level data member rather than a separate copy per object.

84
New cards

Can a static function directly access ordinary non-static members?

No, because it has no this pointer.

85
New cards

What is operator overloading?

Defining how an operator works with a user-defined class.

86
New cards

How is operator overloading different from function overloading?

Operator overloading defines an operator function; function overloading uses one function name with different parameter lists.

87
New cards

What is the principle of least privilege?

Give code only the access it needs, often using const and private members.

88
New cards

Which operator accesses a member through an object?

.

89
New cards

Which operator accesses a member through an object pointer?

->

90
New cards

Which allocation requires delete[]?

new[].

91
New cards

Which allocation requires delete?

new.

92
New cards

What is the most common array-traversal off-by-one error?

Using <= instead of <.

93
New cards

What is the most common pointer-tracing mistake?

Confusing the pointer address with the value obtained by dereferencing.

94
New cards

What is the most common C-string mistake?

Forgetting that storage must include the terminating \0.

95
New cards

What is the most common class-access mistake?

Using dot on a pointer or arrow on a non-pointer object.

96
New cards

What is the most common dynamic-memory mistake?

Losing the only pointer to an allocation before releasing it.

97
New cards

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.

98
New cards