Pointers to an Array in C++

Pointers to an array is the pointer that points to the array. It is the pointer to the first element of the pointer instead of the whole array but we can access the whole array using pointer arithmetic.

Syntax to Declare Array Pointer

// for array of type: type arr_name[size];   
type *ptr_name = &arr_name

As you can see, this declaration is similar to the pointer to a variable. It is again because this pointer points to the first element of the array.

Note: The array name is also a pointer to its first element so we can also declare a pointer to the array as: type *ptr_name = arr_name;

Pointer to an Array in C++

Pointers in C++ are variables that store the address of another variable while arrays are the data structure that stores the data in contiguous memory locations. In C++, we can manipulate arrays by using pointers to them. These kinds of pointers that point to the arrays are called array pointers or pointers to arrays.

In this article, we will discuss what is a pointer to an array, how to create it and what are its applications in C++.

Before we start discussing pointers to arrays, let’s first recall what are pointer and Arrays:

What are Arrays?

 An array is a collection of elements of similar data types that are stored in contiguous memory locations. The elements are of the same data type. The name of the array points to the memory address of its first element.

The syntax to declare an array in C++ is given below:

datatype array_name[sizeof_array];

What are Pointers?

Pointers are variables that store the memory addresses of other variables or any data structures in C++.

The syntax to declare a pointer is given below:

data_type *pointer_name ;

Similar Reads

Pointers to an Array in C++

Pointers to an array is the pointer that points to the array. It is the pointer to the first element of the pointer instead of the whole array but we can access the whole array using pointer arithmetic....

Examples of Pointer to an Array in C++

Example 1: Program to Demonstrate That Array Name Is the Pointer to Its First Element...

Pointers to Multidimensional Arrays in C++

...

Examples of Pointer to Multidimensional Arrays

...

Applications of Pointers to Arrays in C++

Pointers to multidimensional arrays are declared in a different way as compared to single-dimensional arrays. Here, we also need to mention the information about the dimensions and their size in the pointer declaration. Also, we need to take care of operator precedence of array subscript operator [] and dereference operator * as a little mistake can lead to the creation of whole different pointer....