Pointer arithmetic

A pointer points to memory, and the type of the pointer determines the type of the data that can be accessed through the pointer. So, an int* pointer will point to an integer in memory, and you dereference the pointer (*) to get the integer. If the pointer allows it (it is not marked as const), you can change its value through pointer arithmetic. For example, you can increment or decrement a pointer. What happens to the value of the memory address depends on the type of the pointer. Since a typed pointer points to a type, any pointer arithmetic will change the pointer in units of the size of that type.

If you increment an int* pointer, it will point to the next integer in memory and the change in the memory address depends ...

Get Beginning C++ Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.