Day 7 Flashcards
What is Smatch?
Allows access to string results
What is regex_search()?
Used to determine a match in a target sequence. Returns a Boolean value of true if there was a match, and false if there was no match.
What are the REGEX parameters?
Target sequence (subject) Regular expression (pattern) Matches: return matched data using str()
What does () mean in regard to regular expressions?
Creates a group that may be referenced by a number
What does {} mean in regard to regular expressions?
Specifies the number of times to repeat the previous character
What does \d mean in regard to regular expression?
Shortcut character class that matches any digit character [0-9]
What does \w mean in regard to regular expression?
Shortcut character class that matches any word character [A-Z a-z 0-9]
What does \s mean in regard to regular expression?
Shortcut for character class that matches any whitespace character [\t\n]
What does + mean in regard to regular expressions?
Shortcut that matches one or more of the previous character
What is Regex?
The header file for Regular Expressions. A string that describes data. Defines search patterns. Used for pattern matching, extracting specific info from a document, etc.
What is an Array?
- A memory structure that groups data of the same type in adjacent memory locations in the stack.
- After declared, cannot be changed in size (makes it non-dynamic)
- Special pointer that always points to the base address of the array
- The size of an array is the address of index 0.
What are the [] used for with an array?
Used to indicate the initial array size using an element count.
Can never hold more elements than the initial number inside the brackets.
Analyze: Float grades[8] = {89.5, 75.3, 90.6, 97.8, 62.2, 78.4, 80.7} (0-7)
There are 6 grades, but one not listed is set at 0.0 (this is the last index 7). Therefore there are 8 elements. (One element will be uninitialized)
How do you change the value of the last position available with the array float grades = {89.5, 75.3, 90.6, 97.8, 62.2, 78.4, 80.7, 0.0}?
Indicate the last position as grades [7] = 100.0. This changes the last value 0.0 to 100
What would cause a buffer overflow with the array
Float grades[8] = {89.5, 75.3, 90.6, 97.8, 62.2, 78.4, 80.7?
If the programmer tried to write the value index to eight (not to be confused with elements). Looks like grade[8]. This would reference a ninth element with an array with only enough space for 8 elements..
How do you record the byte size of an array?
int vals[10] = {5, 10, 15, 20, 25, 30, 35, 40, 45, 50};
cout «_space;sizeof( vals ) «_space;” Bytes”
• When you know the number of elements, you multiply that by 4.
• Remember, that each byte of an int or float is 4.
• Therefore, in this problem, if there are 10 elements you would do 4x10 to get the total bytes in the array.
• “sizeof()” is the indicator to execute this.
What is the variable name of an array?
• It is a special pointer. Its value is the address of the first element of the array.
• Contiguous or adjacent
• Example:
o 1. float grades[10] – {10,20,30,40,50,60,70,80,90,100}
o 2. Float *gradeptr = &grades;
o 1. float grades[10] – {10,20,30,40,50,60,70,80,90,100}
o 2. float gradeptr = &grades[0]
*notice that *gradeptr got the value of 0, which is the index number of 10 the first element.