Recall & Review
beginner
What is pointer arithmetic in C?
Pointer arithmetic means adding or subtracting integers to or from pointers to move through memory locations of the data type the pointer points to.
Click to reveal answer
beginner
How does adding 1 to a pointer affect its value?
Adding 1 to a pointer moves it to the next element of its type in memory. For example, if it points to an int, it moves forward by sizeof(int) bytes.
Click to reveal answer
intermediate
What happens when you subtract two pointers?
Subtracting two pointers gives the number of elements between them, not the byte difference. Both pointers must point to elements of the same array.
Click to reveal answer
beginner
Why can't you add two pointers together?
Adding two pointers is not allowed because it doesn't make sense to combine two memory addresses. Pointer arithmetic only supports adding or subtracting integers to pointers.
Click to reveal answer
intermediate
Explain how pointer arithmetic relates to array indexing.
Array indexing like arr[i] is actually pointer arithmetic under the hood. It means *(arr + i), moving the pointer i elements forward and accessing that value.
Click to reveal answer
If p is an int* pointing to address 1000 and sizeof(int) is 4, what is the address of p + 2?
✗ Incorrect
Adding 2 to p moves it 2 elements forward. Each int is 4 bytes, so 2 * 4 = 8 bytes. 1000 + 8 = 1008.
What does the expression (p2 - p1) return if p1 and p2 are pointers to elements in the same array?
✗ Incorrect
Subtracting pointers returns how many elements apart they are, not the byte difference.
Which of these operations is NOT valid in pointer arithmetic?
✗ Incorrect
You cannot add two pointers together. Only add or subtract integers to/from pointers.
What does arr[i] mean in terms of pointers?
✗ Incorrect
Array indexing is pointer arithmetic: arr[i] is the same as *(arr + i).
If p points to a char and p = p + 5, how many bytes does p move forward?
✗ Incorrect
A char is 1 byte, so moving 5 elements forward moves 5 bytes.
Describe what happens when you add an integer to a pointer in C.
Think about how arrays and pointers relate.
You got /3 concepts.
Explain why subtracting two pointers gives the number of elements between them, not the byte difference.
Consider how pointer arithmetic is designed for array navigation.
You got /3 concepts.