Day 7 Flashcards

1
Q

What is Smatch?

A

Allows access to string results

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is regex_search()?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the REGEX parameters?

A
Target sequence (subject)
	Regular expression (pattern)
	Matches: return matched data using str()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does () mean in regard to regular expressions?

A

Creates a group that may be referenced by a number

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does {} mean in regard to regular expressions?

A

Specifies the number of times to repeat the previous character

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does \d mean in regard to regular expression?

A

Shortcut character class that matches any digit character [0-9]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does \w mean in regard to regular expression?

A

Shortcut character class that matches any word character [A-Z a-z 0-9]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does \s mean in regard to regular expression?

A

Shortcut for character class that matches any whitespace character [\t\n]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does + mean in regard to regular expressions?

A

Shortcut that matches one or more of the previous character

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is Regex?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is an Array?

A
  • 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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the [] used for with an array?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What would cause a buffer overflow with the array

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How do you record the byte size of an array?

A

int vals[10] = {5, 10, 15, 20, 25, 30, 35, 40, 45, 50};
cout &laquo_space;sizeof( vals ) &laquo_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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the variable name of an array?

A

• 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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is Pointer Arithmetic?

A

• Since pointers have addresses and values, simple math within the array can manipulate the data at which they point.
note in the example that the pointer will have a value of 0 because it will hold the value of the first element which is 10.
• For example:
o int grades[10] = {10,20,30,40,50,60,70,80,90,100}
o int grade = *(grades + 2)  because the pointer value WAS 0, when we add 2 it now is 2 and points to the 3rd element: 30.
o Int grade = *(grades +6) same concept, we have to find the element that holds the value of 6. This is the 7th element: 70.

17
Q

THIS IS NOT A QUESTION JUST A NOTE:

In a question when it says memory location and inputs something like &1000, you have to add 4bytes per index you go through.

A

Example taken from etc:
• If the base address of the array vals is &1000; what memory location does valsPtr hold at the end of the following code? Int vals[10] = {5, 10, 15, 20, 25, 30, 35, 40, 45, 50};
int *valsPtr = &vals[2];
 Answer explained:
o The question wants you to go to the index of 2, indicated by &val[2] (which is 15). Given the “vals” address given in the problem, you will start your address at 1000 and add 4 bytes (the number of bytes in a int or float) until you are at index 2. The answer would be &1008. Let’s say they wanted index of 4…. Then the answer would be &1016.
o Be careful to note whether they are asking for memory location, memory address, or code.

18
Q

Define: Dynamic Memory Allocation

A

Allows a programmer to request contiguous blocks of memory from the heap

19
Q

Common dynamic memory functions

A

New- allocates enough space for any single built-in or user-defined data, type, class, or structure. Returns a pointer to the allocated memory or nullptr if the allocation failed.
Delete- frees memory allocated with new
New [] – similar to the above except used for arrays. Returns a pointer to the allocated memory or nullptr if the allocation failed.
Delete [] – frees memory allocated with new [] operator.
Memory Leak  using the wrong version of delete

20
Q

How do I know where a variable or value is stored?

A

Everything that we’ve allocated with keyword is coming out of the heap, but we have to store it somewhere in a pointer and if you’re declaring it with a pointer it’s in the stack.
Value = heap
Variable = stack

21
Q

example of heap vs stack

A
EXAMPLE
In which segment of memory is the variable whereAmI located?
#include 
using namespace std;
int main()
{
    int *whereAmI = new int;
    *whereAmI = 42;
    cout << whereAmI;
    return 0;
}
Stack
The variable whereAmI in the following code points to a value stored in memory. In which segment of memory is the value whereAmI points to stored?
#include 
using namespace std;
int main()
{
    int *whereAmI = new int;
    *whereAmI = 42;
    cout << whereAmI;
    return 0;
HEAP