The array is a collection of the same type of elements at contiguous memory locations under the same name.
It is easier to access the element in the case of an array.
The size is the key issue in the case of an array which must be known in advance so as to store the elements in it.
Insertion and deletion operations are costly in the case of an array since the elements are stored at contiguous memory locations.
No modification is possible at the runtime after the array is created and memory wastage can also occur if the size of the array is greater than the number of elements stored in the array.
Array representation:
C++
// C++ code for creating an array
#include <iostream>
usingnamespacestd;
// Driver Code
intmain()
{
// Creating an array
intarr[10]={1,2,3,4,5,6,7,8,9,10};
// Printing the array
for(inti = 0; i < 10; i++)
{
cout << arr[i] << " ";
}
return0;
}
Java
/*package whatever //do not write package name here */
Feeling lost in the world of random DSA topics, wasting time without progress? It’s time for a change! Join our DSA course, where we’ll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 zambiatek!