C++ Program to Access Elements of an Array Using Pointer Last Updated : 16 Jan, 2023 Comments Improve Suggest changes Like Article Like Report Prerequisites: Pointers in C++Array in C++ A Pointer is a variable that stores the memory location or address of an object or variable. In other words, pointers reference a memory location, and obtaining the value stored at that memory location is known as dereferencing the pointer. An Array is the collection of homogeneous elements stored in contiguous memory blocks. So, elements in an array can be accessed using a pointer. Access elements using Pointer Pointer has the capability to store the address, So, we can store the address of the first element of the array and then traverse the pointer till we reach the end element. Methods to store the address of the first elements of the array are mentioned below: int *ptr = arr;int *ptr = &arr[0]; After this, a for loop is used to dereference the pointer and print all the elements and the memory location of the element of the array. At each loop iteration, the pointer points to the next element of the array. Then the array value and address are printed. Let's check the Pointer to array example. Example: C++ // C++ Program to implement the // use of pointer with array #include <iostream> using namespace std; int main() { int arr[5] = { 6, 2, 5, 7, 4 }; // We can use arr or &arr[0] as both will give the // address of first element of the array. int *ptr = // arr; int* ptr = &arr[0]; for (int i = 0; i < 5; i++) { cout << "Value of" << i << " arr[" << i << "] is " << *(ptr + i) << endl; cout << "Address of " << *(ptr + i) << " is " << ptr + i << endl << endl; } return 0; } OutputValue of0 arr[0] is 6 Address of 6 is 0x7ffc9de51fb0 Value of1 arr[1] is 2 Address of 2 is 0x7ffc9de51fb4 Value of2 arr[2] is 5 Address of 5 is 0x7ffc9de51fb8 Value of3 arr[3] is 7 Address of 7 is 0x7ffc9de51fbc Value of4 arr[4] is 4 Address of 4 is 0x7ffc9de51fc0 Comment More infoAdvertise with us Next Article C++ Program to Access Elements of an Array Using Pointer Y yashk9293 Follow Improve Article Tags : Technical Scripter C++ Programs C++ Technical Scripter 2022 cpp-pointer C Array Programs +2 More Practice Tags : CPP Similar Reads How to Access Elements in a Vector of Char Arrays? In C++, a vector is a dynamic array that can grow and shrink in size. A char array is a sequence of characters, typically used to represent strings. In this article, we will learn how to access elements in a vector of char arrays in C++. Example: Input: myVector = {âappleâ, âbananaâ, âcherryâ} Outpu 2 min read How to Find the Size of an Array Using Pointer to its First Element? In C++, arrays are plain old data types that do not have any associated functions to find their size. In this article, we will discuss how we can determine the size of the array in C++ using the pointer to its first element.ExampleInput: int arr[]={1,2,3,4,5}Output:Size of the array is 5Find the Siz 2 min read How to Declare Pointer to an Array of Strings in C++? In C++, an array of a string is used to store multiple strings in contiguous memory locations and is commonly used when working with collections of text data. In this article, we will learn how to declare a pointer to an array of strings in C++. Pointer to Array of String in C++If we are working wit 2 min read How to Delete an Element from an Array in C++? In C++, arrays are data structures that allow users to store data of the same type in contiguous memory locations. In this article, we will learn how to delete an element from an array in C++. Example: Input:myarr = {20, 5, 1, 10, 15};Target: 1Output:Array after deletion: 20 5 10 15Remove an Element 3 min read Different ways of accessing array elements in C++ In this article, two unique and different ways of accessing an element from an array rather than the conventional arr[i] expression are discussed below. Using pointer *(arr+1)Using a little manipulation i[arr] for using arrays and the reason behind that. When a C++ program is compiled, a symbol tabl 4 min read How to Find the Sum of Elements in an Array in C++? In C++, an array is the collection of similar data elements that are stored in the contiguous memory location and we can access these elements directly by their index value. In this article, we will learn how to find the sum of elements in an array in C++. Example:Input: myVector = {1, 2, 3, 4, 5} O 2 min read Array of Pointers to Strings in C++ In C++, an array is a homogeneous collection of data that is stored in a contiguous memory location. We can store almost all types of data as array elements. In this article, we will learn how to store the array of pointers to strings in C++. Array of Pointers to Strings in C++A pointer to a string 6 min read How to Find the Index of an Element in an Array in C++? Given an array of n elements, the task is to find the index of a specific element in C++.ExamplesInput: arr[] = {11, 13, 9, 21, 51, 1000}, val = 9Output: 2Explanation: As the value 9 is present at index 2.Input: arr[] = {5, 8, 12, 9, 11, 32}, val = 11Output: 4Explanation: As the value 11 is present 3 min read How to Find All Indexes of an Element in an Array in C++? In C++, an array is a collection of elements of the same type placed in contiguous memory locations. In this article, we will learn how to find all indexes of a specific element in an array in C++. Example: Input: myArray = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4}; target = 3Output: The element 3 occurred at 2 min read How to Read and Write Arrays to/from Files in C++? In C++, an array is a collection of elements of the same type placed in contiguous memory locations. A file is a container in a computer system for storing information. In this article, we will learn how to read and write arrays to/from files in C++. Example: Input: Array = {1, 2, 3, 4, 5}Output: // 2 min read Like