AD Blocker Detected

Ads can be a pain, but they are our only way to maintain the server. Please deactive Ads blocker to read the content. Your co-operation is highly appreciated and we hope our service can be worth it.

Hey yo, what’s up today I’m a little kind of curious to write an article about Array. Hope this article might help you to become the better version of yourself in your tech career.

So you might be wondering, what the heck is Array? This sounds weird to me. I haven’t heard this term. How can I know about it and what are the requirements to know about it? You just need some basic concepts of programming to understand Array. It’s simple, just give time to this article to understand like you used to do with your girlfriend I know its that feeling. Take your time and be cool. Ok, let’s learn rather diverging your mind to something else.

You might me know about a few mathematical concepts like matrix, algebra. These mathematical operations can be implemented by using Array.

An array is a collection of homogeneous data elements, in the form of index/value pairs, which is stored in consecutive memory locations.

An Array is one of the oldest data structures which is still used by software engineers.

The main idea of An Array is to store multiple data items of the same type together.

Why Array?

  • Arrays are fast because you can easily access elements using an array index.
  • You can perform traversal through the array which becomes easy using a single loop.
  • You can also sort elements using less line of code.
  • You can also perform random access to the elements using array.
  • Last but not least, it helps you to pass the data structures exam. Just kidding.
  • Arrays are asked in coding interviews.

Types of Array

  • One Dimensional Array
  • Multi-Dimensional Array

Terms

  • Array Index – The location of an element in an array has an index, which identifies the element. The array index starts from 0.
  • Array Element – Items stored in an array is called an element. The element can be accessed via its index.
  • Array Length – The length of an array is defined based on the number of elements an array can store.

Declaration of Array

There are many ways in which we can declare an array. It can be done by specifying its type and size, by initializing it or both.

Array declaration by specifying the size

int array[15];

Array declaration by initializing elements

int array[] = {1,4,5,5,0}

Array declaration by specifying size and initializing elements

int array[5] = {2,3,7,4,3}

Operations of Array

You knew the basic concepts of the array, right? Let’s know the operations of Array too.

  • Traverse – Prints all the elements in Array one by one.
  • Insertion – Adds an element at the particular index.
  • Deletion – Delete an element at the particular index.
  • Search – Searches an element in the array using the given index or the value.
  • Update – Updates an element at the given index.

Well, this is the fact that Arrays Index always starts from 0. There is still a conversation about it why it should start from 0 or 1 in a few forums and groups.

int cat[15];

Here cat itself is a pointer that contains the memory location of first element of an array. If we access the first element. we write code like this.

cat[0];

Here, the compiler decoded internally as *(cat+0). In the same way, if we access the second element.

cat[1];

As the cat contains the address of the first element, and when we access the second one, we have to add 1 to it like this *(cat+1) which is done by the compiler. In order to improve the performance and optimization of large programs, the array’s index starts from zero.

Conclusions

Hello readers, hope you learn something today valuable. I will be writing an Array series and share many things of an array. Stay connected and keep coding.

Uncategorized