Used to store multiple elements of the same data type under a single identifier.
They can be accessed using an index that starts from 0
Syntax:
data_type array_name[size];
#include <stdio.h>
int main() {
int numbers[5] = {1, 2, 3, 4, 5};
printf("Element at index 0: %d\n", numbers[0]);
printf("Element at index 2: %d\n", numbers[2]);
return 0;
}
See how the array works
Using the index we can change or modify the values in an array.
#include <stdio.h>
int main() {
int numbers[5] = {1, 2, 3, 4, 5};
numbers[1] = 6;
numbers[2] = numbers[1];
printf(numbers[1]);
printf(numbers[2]);
return 0;
}
We can access, modify the array using loops.
Using iterations in for and while loops we can access them through index.
#include <stdio.h>
int main() {
int numbers[5] = {1, 2, 3, 4, 5};
for (int i = 0; i < 5; i++) {
printf("%d ", numbers[i]);
}
return 0;
}
The Concepts and codes you leart practice in Compilers till you are confident of doing on your own. A Various methods of examples, concepts, codes availble in our websites. Don't know where to start Down some code examples are given for this page topic use the code and compiler.