Accessing Array Elements

In C language, you can access array elements by using the array index notation, which is as follows:


Here, array_name is the name of the array and index is the index of the element you want to access. Array indexing in C starts from zero, which means the first element of the array has an index of 0, the second element has an index of 1, and so on.

For example, if you have an array of integers named my_array and you want to access the third element of the array, you can use the following syntax:

int my_array[5] = {1, 2, 3, 4, 5};
int third_element = my_array[2]; // index 2 refers to the third element

In this example, third_element will be assigned the value 3, which is the value of the third element of the my_array array.

You can also use array indexing to modify the value of an array element, like this:

my_array[2] = 10; // change the value of the third element to 10

In this example, the third element of the my_array the array is changed from 3 to 10.

Add a Comment

Your email address will not be published. Required fields are marked *