Pointers Flashcards
How can i get the address of the variable A?
&A will return the address of the variable A
What is the following coded doing?
int v = 42;
int *ptr = &v;
Creating a integer variable, and storing the address of this variable in the integer pointer ptr.
How many bits does a pointer take up?
This depends on the system architecture.
typedef struct {int a} mystruct;
mystruct m = {10};
mystruct *ptr = &m;
How can I access the a attribute of m using its pointer?
*(ptr).a;
Why are pointers useful in function calls?
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
What does the arrow operator -> do?
p->A
First it de-references the pointer p, and then it accesses the attribute A.