0
0
C++programming~5 mins

Pointers and arrays in C++ - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a pointer in C++?
A pointer is a variable that stores the memory address of another variable. It 'points' to the location where data is stored.
Click to reveal answer
beginner
How are arrays and pointers related in C++?
The name of an array acts like a pointer to its first element. You can use pointers to access array elements by moving through memory addresses.
Click to reveal answer
intermediate
What does the expression *(arr + i) mean?
It means accessing the element at index i of the array arr by moving i positions from the start address and dereferencing the pointer.
Click to reveal answer
beginner
How do you declare a pointer to an integer in C++?
You declare it like this: int* ptr; where ptr can store the address of an integer variable.
Click to reveal answer
intermediate
What happens if you increment a pointer pointing to an array element?
Incrementing the pointer moves it to the next element in the array, because it increases the address by the size of the element type.
Click to reveal answer
What does the pointer variable store?
ASize of a variable
BValue of another variable
CType of a variable
DMemory address of another variable
If int arr[5];, what does arr represent?
APointer to the last element of arr
BPointer to the first element of arr
CValue of the first element
DSize of the array
What does *(arr + 2) access?
AThird element of arr
BSecond element of arr
CFirst element of arr
DFourth element of arr
How do you declare a pointer to a float variable?
Afloat* ptr;
Bptr* float;
Cfloat ptr*;
Dpointer float ptr;
What happens when you do ptr++ if ptr points to an int array element?
APointer value stays the same
BPointer moves to the next byte
CPointer moves to the next int element
DPointer moves to the previous element
Explain how pointers and arrays are connected in C++.
Think about how the array name can be used like a pointer to the first element.
You got /3 concepts.
    Describe what happens when you increment a pointer that points to an array element.
    Consider how memory addresses change when moving through an array.
    You got /3 concepts.