A. malloc
Q 2. What will this code print?
int arr[] = new int [5];
System.out.print(arr);
A. 0
B. value stored in arr[0].
C. 00000
D. Garbage value
Q 3. Which of these is an incorrect Statement?
A. It is necessary to use new operator to initialize an array.
B. Array can be initialized using comma separated expressions surrounded by curly braces.
C. Array can be initialized when they are declared.
D. None of the mentioned
Q 4. State the output
public void show()
{
int arr[]=new int[5], i=0;
while(i<5)
arr[i]=++i;
for(i=0; i<5; i++)
System.out.print(" "+ arr[i]);
}
A. 1 2 3 4 5
B. 0 1 2 3 4
C. Garbage Value 1 2 3 4
D. 1 2 3 4 Garbage Value
Ans: A
Q 5. State the output
public void show()
{
int a[] = {5, 1, 15, 20, 25};
int i, j, m;
i = ++a[1];
j = a[1]++;
m = a[i++];
System.out.print( i + ":"+ j +":" + m);
}
A. 6:7:8
B. 4:5:6
C. 3:2:15
D. 2:3:4
Ans: C
Q 6.State the output
int a[] ={2,4,6,8,10};
a[0]=23;
a[3]=a[1];
int c= a[0]+a[1];
System.out.println("Sum = "+c);
A. Sum = 6
B. Sum = 27
C. Sum = 10
D. Sum = 31
Ans: B
Q 7.State the output
int a[4]={2,4,6,8};
for(i=0;i<=1;i++)
{
s=a[i]+a[3-i];
System.out.print(s+ " ");
}
A. 8 10
B. 10 10
C. 10 12
D. 8 12
Ans: B
Q 8. Difference between Subscript and Subscripted variable
Subscript is the index of the element in the array whereas Subscripted variable is the name of the array when it is used with a subscript to access a single element of the array.
Q 9. Difference between Ordinary variable and array variable
An ordinary variable can hold only one value whereas an array variable can refer to a group of values of the same data type by using a subscript.
Q 10. Difference between sorting and searching
Sorting | Searching |
Sorting means to arrange the elements of the array in ascending or
descending order. | Searching means to search for a term or value in an array. |
Bubble sort and Selection sort are examples of sorting techniques. | Linear search and Binary search are examples of search techniques. |
Q 11. Difference between Linear search and Binary search
Linear Search | Binary Search |
Linear search works on sorted and unsorted arrays | Binary search works on only sorted arrays (ascending or descending) |
Each element of the array is checked against the target value until
the element is found or end of the array is reached | Array is successively divided into 2 halves and the target element is
searched either in the first half or in the second half |
Linear Search is slower | Binary Search is faster |
Selection sort | Bubble sort |
Selection Sort selects the smallest element from unsorted sub-array
and swaps it with the leftmost unsorted element. | Bubble Sort compares adjacent elements and swaps them if they are in
wrong order. |
Performs lesser number of swaps to sort the same array relative to
Bubble Sort | Performs more number of swaps to sort the array |
Selection Sort is faster | Bubble Sort is slower |
Q 13. length and length()
length |
length() |
length is an attribute i.e. a data member of array. |
length() is a member method of String class. |
It gives the length of an array i.e. the number of elements stored in
an array. |
It gives the number of characters present in a string. |
Q. 14 What are the advantages of array
Ans: Using array we can store number of values of same time in same named space location. Also we can access any location value directly.
Q. 15 What are the limitations of array
Ans: There are many limitations of array. Array can store number of values but all are of same type. We can not store different type of values in a single array. An int type array can hold only int values.
Dynamic insertion and deletion of elements on array can be done but it is critical.
Q. 16 Why String is preferred over char type array
Both char type array and String are objects but array has only one data member - 'length' while String class has many methods and data members. Manipulation of String can be easily done through it's functions which is tough in case of char type array.
Q. 17 What are the advantages of index in array
There are many advantages of index in array. We can directly access any location value using the index. The array elements can be displayed from left to right or right to left using the index.
Q. 18 What are the different process of creating a numeric array
We can create an numeric array using the following techniques
1. int a[];
a=new int[10];
2. int a[]=new int[10];
3. int a[]={1,2,3,4,5};
Q. 19 State the relationship between array and loop
Loop and array are closely tied together. We need loop while assigning user input values in an array. We need loop to display array elements and any kind of searching and sorting of array elements, loop is essential.
Q. 20 If we pass an array to a function, is it call by value or call by reference?
If we use array as actual parameter or formal parameter, it is call by refernce.
No comments:
Post a Comment