Engineering Science 1036A/B Lecture 20: Pointers: Pointer Arithmetic
Arithmetic Operators
4 arithmetic operations are supported
+,-,++,--
○
Only integers can be used in these operations
○
2 pointers can be subtracted from each other but can not be added to
each other
○
•
Arithmetic operations is performed relative to the base type of the variable (int,
double)
•
++: increment pointer to point to the next object
•
--: decrement pointer to point to the previous object
•
•
Assignment/Equivalent Operators
Both assignment and equivalent operators can be used with pointer variables
•
Example
Practice pointers problem
Pointer Arithmetic