Tuesday, September 13, 2005

Arrays

TWO MARK QUESTIONS:

1) Define Array
Array is a finite, ordered set of homogeneous elements.
Finite- Specific number of elements in the array.
Ordered- elements are arranged in sequential locations
Homogeneous-all elements in array must be of same type.


2) What are the basic operations that could be performed on an array? Explain.
The Basic Operations are
i) Extraction – It needs array and index from which the element need to be extracted. It return the element of array. X=a[i];
ii) Storing – It needs the array, index and the element to be stored. A[i]=x;


3) What is lower bound and upper bound in an array?
The smallest element of an array’s index is called its lower bound. The highest element of an array’s index is called its upper bound.


4) What is a one-dimensional array? What is the use of it?
One-dimensional array use a single index for reference of array elements. It is used when large number of items should be kept in memory and reference all elements in a uniform manner.


5) What are the advantages of using array?
i) It allows the programmer to declare single identifier and obtain a large amount of space.
ii) It allows programmers to reference each element of the group in a uniform manner, instead of using separate identifier for each.


6) What is base address in an array? How will you reference ith element in array?
The address of the first element in an array is called the base address of array. The ith element in an array could be referenced with
Baseaddress + (index * elementsize)


7) What are two-dimensional arrays?
The component type of a array can be another type. They use two indices for referring each element.
Two-dimensional array can be declared as datatype arrayname[index1][index2]
(eg) int a[3][5];


OTHER QUESTIONS:
1) Write the ADT specification for array. (6 marks)
2) What are the methods to implement array for varying length strings? (8 marks)
3) How will you pass an array to a function? Give example.(6 marks)
4) Explain about Character Strings in C. What are the operations that could be performed in Character strings? Write C function for each. (12 marks)
5) What are the different methods to implement two dimensional array in memory?

Works for you…
1) Write a C program to read 20 integers and to find the average of them. Also find how much each deviate from average.

2) Consider a 2 dimensional array declared as int a[10][15]. Assume each unit requires 1 unit for storage. If the base address is 1000, what is the address of a[4][5], a[9][9] and a[10][15].