Pointers Flashcards

1
Q

What is a pointer?

A

This is essentially where the variable register address is passed to a variable.

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

How is a pointer done?

A

We give the variable the * character and assign it the address of another variable by equating it.
e.g.
int *pointer = variable;

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

When calling a pointer what are the two things we can get from it?

A

Variable address = pointer;

Variable value = *pointer;

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

What is dangling?

A

This is when a pointer is not initialised with a location.

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

What location does a dangling pointer point to?

A

A random address

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

how can you prevent a dangling pointer?

A

By assigning it to nullptr

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

What is pass-by-value?

A

This is where in a function you pass the value of a variable into another function. When that function changes the value of that variable, it changes it only within that function not globally

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

What is pass-by-reference

A

This is where in a function youu pass a variable by reference into another function. When that function changes the value of theat variable, it changes it globally.

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

How can pointers be used to locate variables in an array?

A

If you know the address of an array then you can add a number to that address to find the elemnts within that array

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

Show how a pointer can be used to locate the 5th variable in an array?

A

int array[6] = {a,b,c,d,e,f};

int element_5 = *(array + 5);

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

How do we pass an array into another function?

A
void function(int array[]) {
};
How well did you know this?
1
Not at all
2
3
4
5
Perfectly