Determine whether the following array decalarations are vali
Determine whether the following array decalarations are valid. If a declaration is valid, determine the size of the array.
A) int list[ ] = {18, 13, 14, 16};
B) int x [10] = {1, 7, 5, 3, 2, 8};
C) double y[4] = {2.0, 5.0, 8.0, 11.0, 14.0};
D) double lengths[ ] = {8.2, 3.9, 6.4, 5.7, 7.3};
E) int list [7] = {12, 13, 14, 16, , 8};
F) string names[8] = {\"John\", \"Lisa\", \"Chris\", \"katie\"};
Solution
Answer :
Determine whether the following array decalarations are valid. If a declaration is valid, determine the size of the array.
A) int list[ ] = {18, 13, 14, 16};
Answer :
It is a valid declaration
Size of the array is 4
Explanation :
1.The ArrayList type is int.
2.Initializing with values are
list[0]=18
list[0]=13
list[0]=14
list[0]=16
3. The ArrayList contains 4 values,so arraysize is 4.
...........................
C) double y[4] = {2.0, 5.0, 8.0, 11.0, 14.0};
Answer :
It is invalid declaration.
Explanation :
Arraylist size is 4 but we are initializing 5 elements.So,it is invalid declaration.
...........................
D) double lengths[ ] = {8.2, 3.9, 6.4, 5.7, 7.3};
Answer :
It is a valid declaration
Size is 5
Explanation :
1.The ArrayList type is double.
2.Initializing with values are
lengths[0]=8.2,
lengths[1]=3.9,
lengths[2]=6.4,
lengths[3]=5.7,
lengths[4]=7.3;
3.The ArrayList contains 5 values,so arraysize is 5.
..................................
E) int list [7] = {12, 13, 14, 16, , 8};
Answer :
It is invalid declaration.
Explanation :
{12, 13, 14, 16, , 8};
In this we are find that double comma (, ,).So it is wrong declaration.
...................
![Determine whether the following array decalarations are valid. If a declaration is valid, determine the size of the array. A) int list[ ] = {18, 13, 14, 16}; B) Determine whether the following array decalarations are valid. If a declaration is valid, determine the size of the array. A) int list[ ] = {18, 13, 14, 16}; B)](/WebImages/37/determine-whether-the-following-array-decalarations-are-vali-1110893-1761588997-0.webp)
![Determine whether the following array decalarations are valid. If a declaration is valid, determine the size of the array. A) int list[ ] = {18, 13, 14, 16}; B) Determine whether the following array decalarations are valid. If a declaration is valid, determine the size of the array. A) int list[ ] = {18, 13, 14, 16}; B)](/WebImages/37/determine-whether-the-following-array-decalarations-are-vali-1110893-1761588997-1.webp)