Pointers vs Array in C++ Last Updated : 15 May, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report Arrays and pointers are two derived data types in C++ that have a lot in common. In some cases, we can even use pointers in place of arrays. But even though they are so closely related, they are still different entities. In this article, we will study how the arrays and pointers are different from each other in C++. What is an Array?An array is the collection of multiple items of the same type stored in contiguous memory locations. While declaring Arrays, the size should be mentioned and their indexing starts from 0 in C++. The position of each element can be calculated by adding an offset to the base value, i.e., the memory location of the first element of the array. Syntax datatype var_name[size_of_array] = {elements};Example C++ // C++ Program to demonstrate the arrays #include <iostream> using namespace std; int main() { int i, j; // Declaring array int a[5]; // Insert elements in array for (i = 0; i < 5; i++) { a[i] = i + 1; } // Print elements of array for (j = 0; j < 5; j++) { cout << a[j] << " "; } return 0; } Output1 2 3 4 5 What are Pointers?A pointer is the symbolic representation of addresses. It stores the address of variables or memory location. Pointers enable programmers to create and manipulate dynamic data structures. Variables can be of type int, array, char, function, or any other pointer. Syntax datatype *var_name;Example: C++ // C++ program to implement Pointers #include <iostream> using namespace std; // Driver code int main() { int a = 20; int* ptr; ptr = &a; cout << a << " " << ptr << " " << *ptr; return 0; } Output20 0x7ffe2ae2d4ec 20Arrays vs PointersThe following table list the points that distinguish the arrays and pointers from each other: S. No. Array Pointer 1. Arrays are declared as type var_name[size];Â Pointers are declared as type * var_name;2. Collection of elements of similar data type.Store the address of another variable.3. The array can be initialized at the time of definition.Pointers can also be initialized at definition.4. The size of the array decides the number of elements it can store.The pointer can store the address of only one variable.5. Arrays are allocated at compile time.Pointers are allocated at run-time.6. Memory allocation is contiguous.Memory allocation is random.7. Arrays are static in nature i.e. they cannot be resized according to the user requirements.Pointers are dynamic in nature i.e. memory allocated can be resized later.8. An array of pointers can be created.A pointer to an array can be created.Related ArticlesPointers in C++Difference between pointer and arrayPointer vs Array Comment More infoAdvertise with us R rinkalktailor Follow Improve Article Tags : C++ Algo-Geek 2021 cpp-array cpp-pointer C-Pointers C-Arrays +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 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 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 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 C Arrays An array in C is a fixed-size collection of similar data items stored in contiguous memory locations. It can be used to store the collection of primitive data types such as int, char, float, etc., as well as derived and user-defined data types such as pointers, structures, etc. Creating an Array in 7 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 C Pointers A pointer is a variable that stores the memory address of another variable. Instead of holding a direct value, it holds the address where the value is stored in memory. It is the backbone of low-level memory manipulation in C. Accessing the pointer directly will just give us the address that is stor 9 min read C++ Interview Questions and Answers (2025) C++ - the must-known and all-time favourite programming language of coders. It is still relevant as it was in the mid-80s. As a general-purpose and object-oriented programming language is extensively employed mostly every time during coding. As a result, some job roles demand individuals be fluent i 15+ min read Operator Overloading in C++ in C++, Operator overloading is a compile-time polymorphism. It is an idea of giving special meaning to an existing operator in C++ without changing its original meaning.In this article, we will further discuss about operator overloading in C++ with examples and see which operators we can or cannot 8 min read Like