References and Pointers Flashcards

1
Q

give existing variables new names
allow modification of arguments or items
avoid copying data

A

references

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

the original iterator

A

pointers

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

int x = 5;
int y = x;
what is the value of y?

A

5

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

int x = 5;
int y = x;
y = 10;
what is the value of x now?

A

5

the line y = x; copied the value of x into y

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

the blank makes a reference

A

& ampersand;

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

a reference is a blank

A

new name for something

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

True or False

you can change what a reference refers to after it is created

A

False

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

One of the main places we use references is with blank

A

function arguments

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

why is the argument for print_vector both const and a reference?

A

a const reference argument avoids the cost of copying the vector, but does not allow the vector to be accidentally modified by the function

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

blank is usually the right way to pass an argument

A

const reference
unless
the function needs to modify the variable passed in
the argument has a simple data type, such as int or double

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

References can be used with blank to allow modification to the value of the items in the container:

A

range-style for loops

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

references and range-style for loops

A

for(int&x : numbers)
{
x = x * 2;
}

for (pair& p : scores)
{
p.second = p.second + 5.0;
}

**no need for iterators

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

blank is like a big vector of bytes

A

memory

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

each byte has an address; the first byte is blank, the second is blank, etc

A

first byte is 0

the second byte is 1

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

Each object is given a blank of those bytes to store its value

A

subsequence
ex: an int is given 4 bytes
a double is given 8 bytes

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

the address of an object is the address of its blank

A

first byte

17
Q

blank is a variable that holds the address of an object in memory

18
Q

blank can refer to another variable

19
Q

to declare a pointer, use blank after the type

20
Q

int x = 5;
int* y;
y = &x;
what does that do

A

int x = 5 is a regular integer
int* y; pointer to an integer
y = &x make y point at x

21
Q

when you are done with the ptr data, be sure to release it with blank

A

delete

delete x;

22
Q

pointers can be made to point at entirely new data using the blank keyword

23
Q

data allocated by new is allocated in an area called blank

A

free store

24
Q

containers like string, vector, and map place their contents in the blank

A

free store

25
most variables are allocated at the end of memory in an area called the blank
call stack
26
data in the free store remains allocated until we use the blank key word
delete key word
27
blank allow you to access and modify another variable
pointers and references
28
require special syntax
pointers such as * deference operator such as & (address-of operator)
29
can be moved to point at a new variable
pointers
30
can reference to entirely new data
pointers
31
also available in pure C
pointers
32
no special syntax
references
33
cannot change which variable is referred to
references
34
cannot refer to entirely new data
references
35
new to C++
references