Pointers in C++

Pointers are variables that store the index values of other variables. In this article, I will introduce you to the concept of Pointers in C ++ programming language.

Introduction to Pointers in C++

A pointer is an address that refers to a location in memory. They are commonly used to allow functions or data structures to know and modify memory without having to copy the memory in question. Pointers can be used with primitive (built-in) or user-defined types.

Also, Read – 100+ Machine Learning Projects Solved and Explained.

Pointers use the “dereference” *, “address of” & and “arrow” -> operators. The ‘*’ and ‘->’ operators are used to access pointed memory, and the & operator is used to get an address in memory.

There are two operators for pointers: Address operator (&): returns the memory address of its operand. Contents-of operator (Dereference) (*): returns the value of the variable located at the address specified by its operator.

Getting Started with Pointers

Every variable is stored in the memory and each memory location has its memory address. It enables us to pass variables by reference. There are two things that you need to remember while working with Pointers:

  1. ‘&’ Operator: It gives the address of the variable.
  2. ‘*’ Operator: It gives the value stored at the address, i.e dereferences the value stored at the address

Let’s see how to implement it in code:

The asterisk (*) is used to declare a pointer for the simple purpose of indicating that it is a pointer. Do not confuse it with the dereference operator, which is used to get the value located at the specified address. They are just two different things represented by the same sign.

I hope you liked this article on the concept of Pointers in C++ programming language. Feel free to ask your valuable questions in the comments section below.

Aman Kharwal
Aman Kharwal

I'm a writer and data scientist on a mission to educate others about the incredible power of data📈.

Articles: 1498

Leave a Reply