Pointers Flashcards

1
Q

int *a

A

a is a pointer to a place where some int can be stored (in function prototype, it means “expect a to be the address of some int”

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

Why are function prototypes beneficial?

A

Helps in debugging by checking the types and counts of all parameters.

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

What does a function prototype do?

A

Acts as a function’s interface; A prototype declares the function name, its parameters, and its return type to the rest of the program prior to the function’s actual declaration.

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

Pointers pass by reference or value?

A

By reference

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

Why are pointers powerful?

A

Because it gives function access to the locations of its parameters

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

What’s the benefit/curse of pointers?

A

Gives you the ability to modify memory not in your own scope (outside your scope).

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

&x vs *x

A

GET the address vs GO there (reverse processes); & is the address-of operator while * is go-there operator

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

Strong pointer

A

“Keep this in the heap until I no longer point to it”

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

Weak pointer

A

“Keep this as long as someone else points to it strongly”

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

Nil

A

The value of an object pointer that does not point to anything (value is 0)

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

All pointers initialize to nil (zero)

A

I.e. All instance variables that are pointers to objects start out with zero

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

Sending messages to an obj that is nil returns zero…

A
int i = [obj methodWhichReturnsAnInt]
// i is zero if obj is nil
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Why us pointers? Reason 1

A

Allow us to pass around anything we want around in memory

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

H

A

Give me access to another functioms’s memory

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