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

A

pointer

18
Q

blank can refer to another variable

A

pointer

19
Q

to declare a pointer, use blank after the type

A

*

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

A

new

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
Q

most variables are allocated at the end of memory in an area called the blank

A

call stack

26
Q

data in the free store remains allocated until we use the blank key word

A

delete key word

27
Q

blank allow you to access and modify another variable

A

pointers and references

28
Q

require special syntax

A

pointers
such as * deference operator
such as & (address-of operator)

29
Q

can be moved to point at a new variable

A

pointers

30
Q

can reference to entirely new data

A

pointers

31
Q

also available in pure C

A

pointers

32
Q

no special syntax

A

references

33
Q

cannot change which variable is referred to

A

references

34
Q

cannot refer to entirely new data

A

references

35
Q

new to C++

A

references