How to extract values from an array in the C language?
In C language, you can retrieve values from an array by iterating through it using loops. The specific code is shown below:
#include <stdio.h>
int main() {
int arr[5] = {1, 2, 3, 4, 5};
int i;
for (i = 0; i < 5; i++) {
printf("%d\n", arr[i]);
}
return 0;
}
The code will print each element value in the array arr one by one. The output result is:
1
2
3
4
5
In the loop, the variable i starts at 0 and gradually increases. Each iteration prints the value of the element at index i in the array arr. By traversing the loop, we can sequentially extract and process the values in the array.