Identify any errors in the following array declarations.
a. int x[4] = { 8, 7, 6, 4, 3 };
b. int x[] = { 8, 7, 6, 4 };
c. const int SIZE = 4;
d. int x[SIZE];
a)
Consider given array declaration:
int x[4] = { 8, 7, 6, 4, 3 };
Error: The name of the array is 'x' and initialized the size is 4. That means, it accepts only 4 elements in the array. But, the given array stored 5 elements, those are (8, 7, 6, 4, 3 ) . So, it denotes an compiler errors. So, the correct array declaration for initilized an array is declared any four elements.
For example: int x[4] = { 8, 7, 6, 4}; (or) int x[4] = { 7, 6, 4, 3 }; ,etc...
b)
Consider given array declaration:
int x[] = { 8, 7, 6, 4 };
Correct: The reason is that, the initialized array size of 'x' is empty. It takes any number of elements in the array. So, given array declaration is correct.
c)
Consider given data:
const int SIZE = 4;
Correct: The constant values always represents in capital letters. The initialized varial name "SIZE" is an constant integer data type and size is 4. It accepts four elements in an array declaration.
d)
Consider given array declaration:
int x[SIZE];
Correct: The constant array name "SIZE" is stored in the variable 'x'. If the array "SIZE" is defined the value is 4, then the array 'x' accepts only four elements.