Accessing Array Elements of C Programming

We can access any array element using array name and subscript/index written inside pair of square brackets [].

For Example:
Suppose we have an integer array of length 5 whose name is marks.

int marks[5] = {5,2,9,1,1};

Now we can access elements of array marks using subscript followed by array name.

  • marks[0] = First element of array marks = 5
  • marks[1] = Second element of array marks = 2
  • marks[2] = Third element of array marks = 9
  • marks[3] = Fourth element of array marks = 1
  • marks[4] = Last element of array marks = 1

Remember array indexing starts from 0. Nth element in array is at index N-1.

C Program to print all Array Elements

Accessing Array Elements of C Programming

#include <stdio.h>
#include <conio.h>
 
int main(){
    int value[7] = {1,2,3,4,5,6,7};
    int i;
    /* Printing array elements using loop */
    for(i = 0; i < 7; i++){
        printf("Element at index %d is %d\n", i, value[i]);
    }
     
    getch();
    return 0;
}

Output

Element at index 0 is 1
Element at index 1 is 2
Element at index 2 is 3
Element at index 3 is 4
Element at index 4 is 5
Element at index 5 is 6
Element at index 6 is 7