What is the method of initializing values in C language arrays?
There are two ways to initialize and assign values to arrays in C language.
- Static initialization: assigning initial values to array elements directly when defining the array, enclosed in curly braces { }, for example:
int arr[5] = {1, 2, 3, 4, 5};
- Dynamic initialization: After defining an array, assigning values to the array elements through a loop or other means, for example:
int arr[5];
for(int i = 0; i < 5; i++) {
arr[i] = i + 1;
}