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 C++ Programming Language C++ is a computer programming language developed by Bjarne Stroustrup as an extension of the C language. It is known for is fast speed, low level memory management and is often taught as first programming language. It provides:Hands-on application of different programming concepts.Similar syntax to 5 min read Object Oriented Programming in C++ Object Oriented Programming - As the name suggests uses objects in programming. Object-oriented programming aims to implement real-world entities like inheritance, hiding, polymorphism, etc. in programming. The main aim of OOP is to bind together the data and the functions that operate on them so th 5 min read Inheritance in C++ The capability of a class to derive properties and characteristics from another class is called Inheritance. Inheritance is one of the most important features of Object-Oriented Programming in C++. In this article, we will learn about inheritance in C++, its modes and types along with the informatio 10 min read Decorators in Python In Python, decorators are a powerful and flexible way to modify or extend the behavior of functions or methods, without changing their actual code. A decorator is essentially a function that takes another function as an argument and returns a new function with enhanced functionality. Decorators are 10 min read 30 OOPs Interview Questions and Answers [2025 Updated] Object-oriented programming, or OOPs, is a programming paradigm that implements the concept of objects in the program. It aims to provide an easier solution to real-world problems by implementing real-world entities such as inheritance, abstraction, polymorphism, etc. in programming. OOPs concept is 15 min read Vector in C++ STL C++ vector is a dynamic array that stores collection of elements same type in contiguous memory. It has the ability to resize itself automatically when an element is inserted or deleted.Create a VectorBefore creating a vector, we must know that a vector is defined as the std::vector class template i 7 min read AVL Tree Data Structure An AVL tree defined as a self-balancing Binary Search Tree (BST) where the difference between heights of left and right subtrees for any node cannot be more than one. The absolute difference between the heights of the left subtree and the right subtree for any node is known as the balance factor of 4 min read Sliding Window Technique Sliding Window Technique is a method used to solve problems that involve subarray or substring or window. The main idea is to use the results of previous window to do computations for the next window. This technique is commonly used in algorithms like finding subarrays with a specific sum, finding t 13 min read What is a Neural Network? Neural networks are machine learning models that mimic the complex functions of the human brain. These models consist of interconnected nodes or neurons that process data, learn patterns, and enable tasks such as pattern recognition and decision-making.In this article, we will explore the fundamenta 14 min read Templates in C++ C++ template is a powerful tool that allows you to write a generic code that can work with any data type. The idea is to simply pass the data type as a parameter so that we don't need to write the same code for different data types.For example, same sorting algorithm can work for different type, so 9 min read Like