10.When an ages array is correctly initialized using the values 120, 30, 40, 50,
ID: 3708400 • Letter: 1
Question
10.When an ages array is correctly initialized using the values 120, 30, 40, 50, as in Question 8, then the value of ages [4] is a. b. 4 c. 50 d. undefined 11. When you declare an array as int temperature 0, 32, 50, 90, 212, 451)the value of emperature.Lengthis a. b. 6 C. d. unknown 12. Which of the following doubles every value in a 10-element integer array named amount? a. for (int x = 9; x >= 0;-x) amount [x] *= 2; b. foreach (int, number in amount) number 2 c. both of these d. neither of these 13. Which of the following adds 10 to every value in a 16-element integer array named points? a. for (int sub 0 sub > 16; ++sub) points[ub10; b. foreach (int sub in points) points10; c. both of these d. neither of theseExplanation / Answer
The answers for your questions are below.
10.When an ages array is correctly initialized using the values {20,30,40,50}, then the value of ages[4] is
Answer: Option d) Undefined.
This will cause an Exception as 4 is not a valid index for the array ages. Array indices start from 0, and ends at n-1, where n is the length of the array.
11. When you declare an array as int[] temperature = {0,32,50,90,212,451};, the value of temperature.Length is
Answer: Option b) 6
Length will return the length of the array, we can see , there are 6 elements in the array temperature, so it will return 6. [obviously, the valid indices are between 0 and 6-1 ]
12. Which of the following doubles every value in 10 element integer array named amount?
Answer: option a) for(int x=9;X>=0;--x) amount[x]*=2;
This code will double all values in the array from rear to front. The second option is invalid as it will throw an error ‘Cannot assign to `number' because it is a `foreach iteration variable’ as the code is trying to double the iteration variable instead of the original array.
13. Which of the following adds 10 to every value in a 16 element integer array named points?
Answer: option d) neither of these
None of the two code snippets in option a and b satisfy the required operation. In the first option, the condition is wrongly put. It should be sub <16 instead of sub > 16, as a result, the control never reaches inside the loop. In the second option, the addition operation is done using array name itself, which is not allowed and is wrong.
I hope everything is clear now. Thanks.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.