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 create a pointer?
type* var, or type var.
ex: int one, int *two
How do you assign stack memory to a pointer?
int target = 7;
int *point =⌖
How is the * character used to dereference?
When put in front of a pointer, it will provide the value in that memory address.
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 an int
What is created with const int &f = …;?
read only reference
How do you use allocated memory with a pointer?
With the ‘new’ keyword.
What are the 2 keyword pairs to remember for heap memory allocation?
new/delete and new[]/delete[]