Arrays in C/C++

Arrays in C/C++

Table of contents

No heading

No headings in the article.

In this post of our series "Basics of C" i will be explaining you Arrays in C I am very much sure that you are already aware about Primitive Data types(int,float,char etc). Now in this one we’ll talk about one of the Non-Primitive Data types in C which is Array.Now the question arises what is an array?

An array in C/C++ or be it in any programming language is a collection of similar data items stored at contiguous memory locations and elements can be accessed randomly using indices of an array.

They can be used to store the collection of primitive data types such as int, float, double, char, etc of any particular type.Since what we are working with is a Programming language and merely this definition is not enough for a beginner coder to understand as to what an array is, so let's take this discussion further with declaring a sample array of 5 integers.

int arr[5]={15,25,35,45,55};

Breakdown of the above syntax:-

  • int here defines as to what the data type of the array is.

  • arr is the name of the array.

  • [5] is the size of the array which defines the number of elements the array contains.

-Note:-Array index starts from 0 till N-1(where N is the size of the array) so 15 here is arr[0]th element.

Types Of Array:-

  1. One-Dimensional array(1-D array) are used to store a list of values of the same data type. One dimensional arrays are also called single dimensional arrays, Linear Arrays or simply 1-D Arrays.

  2. Multi Dimensional Array:-In simple words it can be understood as an array of arrays. Multi dimensional arrays can be of two dimensional type or three dimensional type or four dimensional type or more. Most popular and commonly used multi dimensional array is two dimensional array. Multi dimensional arrays are used to store data in the form of tables(matrix in mathematics language).

Let's take a Sample 2-D Array for better understanding:-

int arr[2][2]={{1,2},{3,4}};

Now if you wish to check the implementation of the above said you can visit my github repo linked below. Github-lnkd.in/d5thZ8tF

If you have reached here thank you for reading Have a great day ahead!