Pointers Flashcards
What is a pointer?
This is essentially where the variable register address is passed to a variable.
How is a pointer done?
We give the variable the * character and assign it the address of another variable by equating it.
e.g.
int *pointer = variable;
When calling a pointer what are the two things we can get from it?
Variable address = pointer;
Variable value = *pointer;
What is dangling?
This is when a pointer is not initialised with a location.
What location does a dangling pointer point to?
A random address
how can you prevent a dangling pointer?
By assigning it to nullptr
What is pass-by-value?
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
What is pass-by-reference
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 can pointers be used to locate variables in an array?
If you know the address of an array then you can add a number to that address to find the elemnts within that array
Show how a pointer can be used to locate the 5th variable in an array?
int array[6] = {a,b,c,d,e,f};
int element_5 = *(array + 5);
How do we pass an array into another function?
void function(int array[]) { };