To access array elements in C using index, you can use square brackets notation.
In this example,
numbers
with integer values.2
using indexing numbers[1]
.#include <stdio.h>
int main() {
int numbers[] = {1, 2, 3, 4, 5};
printf("%d\n", numbers[1]);
return 0;
}
2
In this example,
chars
with character values.3
using indexing chars[2]
.#include <stdio.h>
int main() {
char chars[] = {'a', 'b', 'c', 'd', 'e'};
printf("%c\n", chars[2]);
return 0;
}
c
In this tutorial, we learned How to Access Array Elements using Index in C language with well detailed examples.