Assignment 3 Arrays
Assignment 3 Arrays
2 State whether the following are true or false. If the answer is false, explain why.
(i) an array can store many different types of values.
(ii) An array subscript can be of data type float.
(iii) If there are fewer initializers in an initializer list than the number of elements in
the array, C automatically initializes the remaining elements to the last value in
the list of initializers.
(iv) It is an error if an initializer list contains more initializer than there are elements in
the array.
(v) To refer to a particular location or element within an array, we specify the name of
the array and the value of the particular element.
(vi) An array declaration reserves space for the array.
(vii) To indicate that 20 locations should be reserved for integer array Y, the
programmer writes the declaration as
Y[20];
(viii) to refer to 15th element of an array D the programmer should write
D[15]
(ix) Array elements are scattered in the memory.
(x) Exchanging the values of two array elements is called swaping.
5 Write down a C program that defines two arrays of integers X and Y of size 20 each.
Assign 20 random numbers in array X. Assign 20 entries of array X to array Y such that
X[0] is assigned to Y[19], X[1] is assigned to Y[18], X[2] is assigned to Y[17], and so on
X[19] is assigned to Y[0]. Finally print all the contents of array Y. (perform the task with
the help of for loop)
6 Write down a C program that defines an array of integers X of size 20. assign 20 integers to
X then Swap X[0] to X[19], X[1] to X[18], X[2] to X[117], and so on. (Perform the task
using for loop).