C++Introduction to C++Learn C++

Learn To Use Arithmetics On Pointers In C++

In a previous post, we learned that pointers are variables to point address which is also an integer value. That means we can do arithmetic operations on a pointer variable. But do not forget that we operate on the addresses in our RAMs, so we should be careful and we should know the range well. Simply, we can use ++, –, +, and – arithmetic operators on pointers:

In a 32bit application, the pointer addresses 32bit. So the increment of pointer, when you increase the address 32bits, means that you increase that pointer to 4 bytes forward. If you decrease that pointer, it also means you decrease the address to 4 bytes backward. In a 64bits application, this means 64bits change that results in 8bits forward or backward address.

We can easily understand all these in this example below,

Comparison in Pointers

Pointers are integer values that points address in memory, they can be also compared as integers by using relational operators such as ‘==’, ‘<‘, ‘>’. We can check two pointers if they are pointing the same address, see example below.

‘<‘ and ‘>’ comparison operators can be used in array pointers as given above.


Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome C++ content in your inbox, every day.

We don’t spam! Read our privacy policy for more info.

About author

Dr. Yilmaz Yoru has 35+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux, and some other operating systems. He was born in 1974, Eskisehir-Turkey, started coding in college and graduated from the department of Mechanical Engineering of Eskisehir Osmangazi University in 1997. He worked as a research assistant at the same university for more than 10 years. He received his MSc and PhD degrees from the same department at the same university. Since 2012, he is the founder and CEO of Esenja LLC Company. He has married and he is a father of a son. Some of his interests are Programming, Thermodynamics, Fluid Mechanics, Artificial Intelligence, 2D & 3D Designs, and high-end innovations.
Related posts
C++C++11C++14C++17C++20Learn C++Syntax

What Is A Forced (Default) Copy Assignment Operator In Modern C++

C++C++11C++14C++17C++20Learn C++Syntax

What is Implicitly-declared Copy Assignment Operator In C++?

C++C++11C++14C++17C++20Learn C++Syntax

What is Avoiding Implicit Copy Assignment In C++?

C++C++11C++14C++17C++20Learn C++

Typical Declaration Of A Copy Assignment Operator Without std::swap

Worth reading...
Learn to Use Pointers and Memory Address of a Variable in C++