Arrays in C Language


Array is a collection of same type of elements at contiguous memory location. The lowest address corresponds to the first element while highest corresponds to last element.

Array index starts with zero(0) and ends with the size of array minus one(array size - 1). Array size must be integer greater than zero.

Let us see an example,

If array size = 10
First index of array = 0
Last index of array = array size - 1 = 10-1 = 9

Here is the syntax of arrays in C language,

type array_name[array_size ];

The following is how you can initialize an array.

type array_name[array_size] = { elements of array }

Here is an example of arrays in C language,

Example

 Live Demo

#include <stdio.h>
int main () {
   int a[5];
   int i,j;
   for (i=0;i<5;i++) {
      a[i] = i+100;
   }
   for (j=0;j<5;j++) {
      printf("Element[%d] = %d
", j, a[j] );    }    return 0; }

Output

Element[0] = 100
Element[1] = 101
Element[2] = 102
Element[3] = 103
Element[4] = 104

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 24-Jun-2020

796 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements