Pointers Flashcards
What do pointers do in C++
They point to a location in memory
What is the ‘&’ character
The reference character; a variable with a leading ‘&’ provides the memory address of that variable
How do you declare a pointer?
With the * character.
ex: int* var or int *var
How do you assign stack memory to a pointer?
int var = 7;
int *point =&var;
How is the * character used to dereference?
When put in front of a pointer, it will provide the value in that memory address.
How do you reassign the value in a pointer?
int *pointer = &var;
*pointer = 13;
Given int pointer ‘pointer’, how do you assign the value in pointer’s memory to variable ‘var’?
int var = *pointer;
How is pointer math performed assuming same pointer type?
The pointers will perform arithmatic in the units of the type.
ex: int *one - int *two = 1, assuming they were declared one after the other.
Given array y, what does *y return?
The memory address of the first index.
What is created with int *a;?
Movable pointer to writable int
What is created with const int *b;?
Movable pointer to read-only int
What is created with int *const c;?
unmoveable pointer writable int.
What is created with const int *const d;?
unmovable pointer to read-only int.
What is created with int &e = …;?
read/write reference int
What is created with const int &f = …;?
read only reference