1/51
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
|---|
No study sessions yet.
What is the basic concept of arrays/vectors?
They store multiple elements of the same type in a single structure using indexed positions.
What is a vector in C++?
A dynamic array that can grow or shrink at runtime, defined in
How do you declare a vector of ints named nums?
std::vector
How do you add an element to the end of a vector?
Use nums.push_back(value);
What does vector.size() return?
The number of elements currently in the vector.
How do you access the 3rd element of vector v?
v[2] (indexing starts at 0).
What is vector.at(i) used for?
Safe element access with bounds checking.
What is the purpose of an iteration drill?
Practice looping through arrays/vectors using indices or range-based loops.
How do you iterate through a vector using a for loop?
for (int i=0; i<v.size(); i++) { … }
How do you iterate through a vector using a range-based loop?
for (int x : v) { … }
What are multiple vectors?
Using more than one vector in parallel to store related data.
How do you resize a vector to size 10?
v.resize(10);
What happens when a vector is resized larger?
New elements are default-initialized.
What is vector.back()?
Returns the last element of the vector.
What does pop_back() do?
Removes the last element of a vector.
How can loops modify vectors?
By accessing elements via index and reassigning them.
How can loops copy vectors?
Push each element from one vector into another.
How can loops compare vectors?
Check each element pair to see if they differ.
What is the general technique for swapping two variables?
Use a temporary variable: temp=a; a=b; b=temp;
What common bug occurs when reversing a vector?
Incorrect index boundaries when swapping front/back.
What is the main difference between arrays and vectors?
Arrays have fixed size; vectors are dynamic.
What is a 2D array?
An array with rows and columns, like int a[3][4].
How do you access element (2,3) in a 2D vector?
v[2][3]
What are C strings?
Null-terminated character arrays of type char[].
How do you declare a C string of size 20?
char name[20];
What does strlen() do?
Returns the length of a C string (before '\0').
What does strcpy() do?
Copies one C string into another.
What library is required for C string functions?
What does the cctype library contain?
Character classification functions like isalpha, isdigit.
What does isalpha(c) do?
Returns true if c is an alphabetic letter.
LAB: Output numbers in reverse – key skill?
Loop backward through a vector or array.
LAB: Middle item – key idea?
Indexing the middle: v[v.size()/2]
LAB: Output values below amount – concept?
Conditional filtering while looping.
LAB: Normalize list – concept?
Scale values so they sum to 1 or fit a range.
LAB: Word frequencies – technique?
Loop through words and count occurrences.
LAB: Contains the character – approach?
Loop through string and check each char.
What is a user-defined function?
A reusable block of code declared with a return type, name, and parameters.
What is a void function?
A function that does not return a value.
Why define functions in C++?
To reduce repetition and improve readability.
What is a mathematical function in C++?
A function that performs and returns a calculation.
What does a function with branches mean?
It contains if/else logic.
What does a function with loops mean?
It performs repeated operations inside the function.
What is unit testing for functions?
Testing each function individually with known inputs.
How does function execution work?
Control jumps to the function, runs it, then returns.
What is a common function error?
Forgetting to return a value from non-void functions.
What is pass-by-reference?
Parameters preceded by & allow modifying the original variable.
How do you modify a vector in a function?
Pass it by reference: void f(vector
How do functions work with C strings?
C string parameters are char arrays, often passed as char[].
What is variable scope?
Where a variable can be accessed in the program.
What are default parameter values?
Parameters given a value in the function header if arguments are omitted.
What is function overloading?
Multiple functions with the same name but different parameters.