Unit 4: Programming
Tutorial :Arrays
To be used in week 12, week beginning 13 March 2021.
1. What are the default values for the double and boolean types in an array declaration?
Answer:
(a) double:
(b) boolean:
2. Declare an array of three integers containing 3, 7 and 8 (in that order).
Answer:
3. Given the declaration
int [ ] t a b l e = new int [ 2 ] ;
How long is the array and what is the valid range of indices?
Answer:
(a) Length:
(b) Range:
4. Consider the array arr[] = {1, 3, 4, 2, -1};, which we represent diagrammatically in the table below, if
the following operations (in the stated order) are applied;
(a) arr[0] = a[0] + 1;
(b) arr[1] = a[1] + 2;
(c) arr[2] += a[1];
(d) arr[3] = a[1] + a[2];
what are the final values in the array?
start finish
0 1
1 3
2 4
3 2
4 -1
1
Tutorial :Arrays
To be used in week 12, week beginning 13 March 2021.
1. What are the default values for the double and boolean types in an array declaration?
Answer:
(a) double:
(b) boolean:
2. Declare an array of three integers containing 3, 7 and 8 (in that order).
Answer:
3. Given the declaration
int [ ] t a b l e = new int [ 2 ] ;
How long is the array and what is the valid range of indices?
Answer:
(a) Length:
(b) Range:
4. Consider the array arr[] = {1, 3, 4, 2, -1};, which we represent diagrammatically in the table below, if
the following operations (in the stated order) are applied;
(a) arr[0] = a[0] + 1;
(b) arr[1] = a[1] + 2;
(c) arr[2] += a[1];
(d) arr[3] = a[1] + a[2];
what are the final values in the array?
start finish
0 1
1 3
2 4
3 2
4 -1
1