Invalid Operations
Learn about invalid operations with pointers.
Introduction
There are a few operations that are invalid and don’t make sense on pointers:
- Multiplication and division between pointer and number or pointer and pointer.
- Addition of two pointers.
- Subtraction between two pointers of different types.
These operations are not allowed because they don’t make sense.
Multiplication
Adding a constant value to a pointer makes sense because we know that we move x bytes to the right. Multiplying does not make sense because the result is undefined. Depending on the address, we end up in a different memory location. We can’t say that the resulting memory location is always x bytes to the right.
Get hands-on with 1400+ tech skills courses.