To access array elements in C, you can use indexing with square brackets.
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,
fruits
with string values.#include <stdio.h>
int main() {
char *fruits[] = {"Apple", "Banana", "Orange"};
for (int i = 0; i < 3; i++) {
printf("%s\n", fruits[i]);
}
return 0;
}
Apple Banana Orange
In this tutorial, we learned How to Access Array Elements in C language with well detailed examples.