Arrays Notes
Arrays Notes
Arrays
Question 1
1. int a[-40]
2. int a[40] ✓
3. float a[0 - 40]
4. None
Question 2
1. 10th
2. 9th
3. 11th ✓
4. None
Question 3
1. packets
2. blocks
3. subscripts ✓
4. compartments
Question 4
1. subscripted variable ✓
2. actual variable
3. compound variable
4. none
Question 5
1. dots
2. element name
3. index number ✓
4. none
Question 6
Indicate the error message which displays, if the following statement is executed :
int a[5] = {28,32,45,68,12};
1. Insufficient cells
2. Array index out of bounce
3. Elements exceeding cells
4. None ✓
Question 7
1. assigns 37 to code[1] ✓
2. assigns 25 to code[1]
3. assigns 38 to code[3]
4. assigns 42 to code[0]
Question 8
1. from 1 to 50
2. from 0 to 49 ✓
3. from 1 to 51
4. none
Question 9
1. m.size of (a)
2. m.elements of (m)
3. m.length ✓
4. None
Question 10
A Single Dimensional array contains N elements. What will be the last subscript?
1. N-1 ✓
2. N
3. N+1
4. None
Question 1
Output
4 6
Explanation
Question 2
Output
Sum = 27
Explanation
a[0]=23 assigns 23 to the first element of the array. a[3]=a[1] assigns the value of
second element of the array which is 4 to the fourth element of the array. After the
execution of these two statements array looks like this:
a[0]+a[1] ⇒ 23 + 4 ⇒ 27
{23, 4, 6, 4, 10}
Question 3
Output
12
Explanation
a[2+1] ⇒ a[3] ⇒ 12
Question 4
int a[4]={2,4,6,8};
for(i=0;i<=1;i++)
{
s=a[i]+a[3-i];
System.out.println(s);
}
Output
10
10
Explanation
i Output Remark
⇒2+8
a[0] + a[3]
⇒10
0 First Iteration
⇒4+6
a[1] + a[2]
⇒10
1 Second Iteration
Question 1
Question 2
Question 3
Variables are useful for keeping track of a single piece of information but as
we collect more and more information, keeping the variables organized can be
complicated. In such situations, we need arrays to solve the problems in a
much better and efficient way.
Question 4
The data type that represents a number of similar or different data under
single declaration is called as composite data type. An array is a group or a
collection of same type of variables. Hence, Array is a composite data type.
Question 5
A Single Dimensional Array contains one row and one or more columns. The
syntax of declaring a Single Dimensional Array is:
<type> <array-variable>[] = new <type>[<size>];
OR
<type> [] <array-variable> = new <type>[<size>];
Question 1
char a[5] is an array of char data type that can hold 5 characters whereas int
a[5] is an array of int data type that can hold 5 integer values.
Question 3
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.
Question 4
Sorting Searching
Sorting means to arrange the elements of the Searching means to search for a term or
array in ascending or descending order. value in an array.
Bubble sort and Selection sort are examples of Linear search and Binary search are
sorting techniques. examples of search techniques.
length length()
It gives the length of an array i.e. the number of It gives the number of characters
elements stored in an array. present in a string.