Pointers Flashcards

1
Q

How can i get the address of the variable A?

A

&A will return the address of the variable A

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

What is the following coded doing?

int v = 42;
int *ptr = &v;

A

Creating a integer variable, and storing the address of this variable in the integer pointer ptr.

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

How many bits does a pointer take up?

A

This depends on the system architecture.

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

typedef struct {int a} mystruct;

mystruct m = {10};
mystruct *ptr = &m;

How can I access the a attribute of m using its pointer?

A

*(ptr).a;

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

Why are pointers useful in function calls?

A

Allow us to avoid having to pass large data structures, which requires a lot of copying

Allows us to return multiple values in a function call

Allows us to pass a variable by reference

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

What does the arrow operator -> do?

p->A

A

First it de-references the pointer p, and then it accesses the attribute A.

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