Array - Introuduction, Declaration and Initialization of an array | Tutorials for beginners | Coding classpoint

ARRAY





Array is the collection of similar data types or collection of similar entity stored in contiguous memory location. Array of character is a string. Each data item of an array is called an element. And each element is unique and located in separated memory location. Each of elements of an array share a variable but each element having different index no. known as subscript. 

An array can be a single dimensional or multi-dimensional and number of subscripts determines its dimension. And number of subscript is always starts with zero. One dimensional array is known as vector and two dimensional arrays are known as matrix.

ADVANTAGES: array variable can store more than one value at a time where other variable can store one value at a time.

Example: 

int arr[100];
int mark[100];

DECLARATION OF AN ARRAY :

Its syntax is : 

Data type array name [size]; 
int arr[100]; 
int mark[100];
int a[5]={10,20,30,100,5}

The declaration of an array tells the compiler that, the data type, name of the array, size of the array and for each element it occupies memory space. Like for int data type, it occupies 2 bytes for each element and for float it occupies 4 byte for each element etc. The size of the array operates the number of elements that can be stored in an array and it may be a int constant or constant int expression.

We can represent individual array as :

int ar[5]; 
ar[0], ar[1], ar[2], ar[3], ar[4]; 

Symbolic constant can also be used to specify the size of the array as:

#define SIZE 10;

INITIALIZATION OF AN ARRAY: 

After declaration element of local array has garbage value. If it is global or static array then it will be automatically initialize with zero. An explicitly it can be initialize that 

 Data type array name [size] = {value1, value2, value3…} 

Example: 

 int ar[5]={20,60,90, 100,120}

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.