// designated initialization --> it's a way to initialize elements of an array by it's index,
// and set the value of the other elements to 0
// ex 1
int arr[5] = {[2] = 5, [3] = 10};
for (int i = 0; i < 5; i++)
{
printf("%d ", arr[i]); // 0 0 5 10 0
}
// ex 2
int arr[10] = {1, 7, [2] = 5, [3] = 10};
for(int i = 0;i<10;i++){
printf("%d ", arr[i]); // 1 7 5 10 0 0 0 0 0 0
}
// ex 3
int arr[ ] = {2, [5] = 1}; // size is 6
printf("%lu", sizeof(arr)); // 24 --> 6 * 4
int[] numbers = new int[5]; /* size of the array is 5 */
int[] nums = new int[] {1, 2, 3, 4, 5}; /* Fill the array ny these numbers*/
String[] names = new String[10]; /* array of type string and size 10 */
String[] countries = new String[] {"Germany", "US"};
The array will be initialized to 0 if we provide the empty initializer list or just specify 0 in the initializer list.
int arr[5] = {}; // results in [0, 0, 0, 0, 0]
int arr[5] = { 0 }; // results in [0, 0, 0, 0, 0]