Simple Questions On Arrays Concept In Data Structures

Ram Pothuraju

1. An array of n elements will be declared in c as:
a. array[n]
b. array[n-1]
c. array[n+1]
d. array
Ans  :  a.  array[n]

2. The first element of a 0 based array can be accessed by : 
a. array
b. array[0]
c. array[n-1]
d. array[n]
Ans.  :  a.  &  b.  array[0] is obvious.. and array is actually pointing toward the first element of the array.

3. What will the piece of code reveal…
   int a[] = {1,2,3,4,5,6,7,8,9,0};
** Regarding the fact that there are no syntax errors..
a. 3 8
b. Logical error
c. 3 3
d. 3 <Garbage Value>
Ans.  c. both will be resolved as (address of a + 2), so both will yield the same address.

4. Memory is allocated in an array in : 
a. Non Continues Way
b. Continues fashion
c. It may be any way, does not matter
d. Random but in some logical manner according to some algorithm.
Ans. :  b.. Memory is indeed allocated in a continues manner, that is the reason why arrays can offer random access while linked lists cant.

5. A ‘n’ sized 1 based array indexed from:
a. [1] – [n]
b. [0] – [n]
c. [1] – [n-1]
d. [0] – [n-1]
Ans. : a     An array may be 0 based, 1 based or n based. Now whichever it is based on that number decides its starting and ending index.

6. How is this resolved..
a. *(&Arr + 2)
b. Arr[0] + 2
c. The Second position from Arr[0]
d. *(Arr + 2)
Ans. : a.    Arr always refers to the first element of the array.. and the index is added to the base address of the array to get the result.

7. Lower bound and Upper bound of an Array represent the following element..
a. Largest and Smallest Resp.
b. Smallest and Largest + 1
c. Smallest and Largest – 1
d. Smallest and Largest Resp.
Ans.:  d., Lower bound represents the first element of the array and upper bound represents the last element of the array.

8. In an Array the range specifies…
a. Scope of the Array
b. Nos. of Elements in the Array
c. The Group of the Array
d. Size – 1 of the Array
Ans.  :   b., Range Specifies the total nos of elements in an Array.

9.If Array’s upper bound is specified by ‘U’ and lower bound is specified by ‘L’  
           then the range of the array will be.
a. U – L +1 
b. L + U – 1
c. U – L – 1
d. L – U + 1
Ans.  :a The range of the array will be Upper  - Lower + 1

     10 .  If  Upper bound is represented by 99 and lower bound by 0 in a o based array, then the range of the array is..

a. 0
b. 99
c. 100
d. 101
Ans. :  c., Range is given by Upper – Lower  + 1
11. A string is ended by…
a. The Last Character
b. The Null Character
c. The Dot Character
d. The First Character
Ans. : b, A string in C is Always Ended by a Null Character.

12. Suppose that you want to declare an array of characters to hold a C++ string with exactly 9 letters. Which declaration is best? 
a. char s[8]; 
b. char s[9]; 
c. char s[10]; 
d. char s[11]; 
e. char s[12]; 
Ans : c, you will need 10 cells, 9 to hold the 9 characters and the last  one cell to hold the end of the string

13.    Which of the following can be used to describe arrays as well as hard disks?  
a. static  
b. dynamic  
c. direct access  
d. linked access 
e. linked
Ans. : c.

      14.    Of the following, which would access an element of an array of records? 
a. Data[i]  
b. Data(i)  
c. Data(i,j)  
d. Data.i  
e. Data[i].f
Ans. : a
     15.    Arrays are also called as

1) Dense lists
2) Predefined variables
3) Static data structures
a. 1 and 2
b. 2 and 3
c. 1 and 3
d. All
Ans. : c

16.     If a is an array (which actually is a pointer as such) and a pointer p;
The statement a = p, yields
a. Address of p copied on a
b. Address remains unchanged
c. Leads to an error
d. Address of a is copied on p instead.
Ans. : c, Leads to an error, since array a, is a pointer but a constant pointer. 

Post a Comment


Post a Comment (0)