

Here the idea of an array is to represent many instances by one variable (One derived type). For example, if you want to store and manipulate the age of 100 students you need to create an array of size 100.

We can resolve this issue easily with the help of an array where we just need to create an array of size n, n is the number of students. The situation becomes more worst and difficult when the number of students goes beyond 100. If we use the integer variable like the above declaration, it will be very difficult to manipulate the data and send it to the server. Since age (in the year) is an integer type, we can store it something like below, //integer variables to store student age information Also, we need to send the calculation result and age information to the server. To understand why do we need arrays to let’s consider the situation, suppose you need to get 10 student’s age information and store it for some calculation. Also, generally, the first element is at the lowest address and the last element is at the highest address in an array. You should remember that that the size and type of an array cannot be changed once it is declared. You can take an array name as your choice (but must follow the naming rule). Array Syntax:įor example, if you want to create an array of 10 integers, you have to declare an array as below expression. So at the time of the array declaration, you need to specify the number and type of the elements with the array name. The declaration of a pointer is very important because Array types are characterized by their element type and by the number of elements in the array. It means if you want to get the first element of the array then the index must be 0.Īrray Syntax (Declaration of Array in C/C++): The index of the array always starts with 0. We can easily access the elements using an index in square brackets. array of 5 integers/Įach element of the array is individually referenced by using an index. For example, if you want to store 5 integers, you can create an array for it. You must remember that the element type shall be complete whenever the array type is specified. The data types for all elements must be the same and store at the contiguous memory location.

So let’s first understand that what is an Array?Īn array is essentially a collection of elements. I will start from the beginner and explain each topic very clearly besides that I have already written many articles on array I will include their links at their appropriate location if you want you can check them. Also some important points related to the array that should you know.

You will learn how to declare, initialize and access elements of an array with the help of some programming examples. In this blog post, you will learn the arrays and their working.
