78. How Is Searching In an Arraylist Carried Out?
Answer: For searching an element in an array list, first we traverse the array list and with traversing, we compare each element of array with the given element.
79. Where Can An Element Are Inserted In An Array List?
Answer: Insertion into an arraylist is possible in three ways:
- Insertion at the beginning.
- Insertion at the end.
- Insertion in between.
80. How Is Deletion In An Array List Carried Out?
Answer: Deletion from an array list is possible in three ways:
- Deletion of the first element.
- Deletion of the last element.
- Deletion in between.
81. What Are The Advantages Of Array Lists?
Answer: The major advantage of the array list is that we can easily compute the address of the array through index and we can also access the array element through the index.
82. What Are The Disadvantages Of An Array List?
Answer: The disadvantage of an array list is that we have to keep the total number of elements and array size. We cannot take elements more than array size because array size is fixed. It requires much processing in insertion and deletion of shifting of array elements.
83. What Is The Maximum Number Of Dimensions An Array Can Have In C?
Answer: C allows arrays of three or more dimensions. The exact limit is determined by the
compiler.
84. What Is The Size Of Array int a[5]={1,2} ?
Answer: The size of int array is 2*5=10 bytes as int takes 2 bytes of storage.
85. To Declare An Array S That Holds A 5 Character String, What Would You Write?
Answer: A string is nothing but a char array. It should be declared as char S[5]
86. Why ā&ā Operator Is Not Used With Array Names In A scanf Statement?
Answer: In scanf() statement, the "address of" operator (&) either on the element of the array (e.g. marks[i]) or on the variables (e.g &rate) are used. In doing so, the address of this particular array element is passed to the scanf() function, rather than its value; which is what scanf() requires. BUT many times, the address of zeroth element (also called as base address) can be passed by just passing the name of the array.
87. What are Multidimensional Arrays?
Answer: Multidimensional arrays can be described as "arrays of arrays". For example, a bi-dimensional array can be imagined as a bi-dimensional table made of elements, all of them of a same uniform data type.
int arr[3][5]; represents a bi-dimensional array of 3 per 5 elements of type int.
Similarly a three dimensional array like int arr[3][4][2]; represent an outer array of three elements, each of which is a two dimensional array of four rows, each of which is a one dimensional array of five elements.
For example, the multidimensional array is stored in memory just like an one-dimensional array shown below:
int arr[3][4][2] = { { {1,2},{3,4},{5,6},{7,8} },
{ {9,1},{1,2},{3,7},{4,7} },
{ {6,1},{18,19},{20,21},{22,23} },
};
88. How Is Multidimensional Arrays Defined In Terms Of An Array Of Pointer? What Does Each Pointer Represent?
Answer: An element in a multidimensional array like two-dimensional array can be represented by pointer expression as follows:
*(*(a+i)+j)
It represents the element a[i][j]. The base address of the array a is &a[0][0] and starting at this address, the compiler allocates contiguous space for all the element row-wise. The first element of second row is immediately after last element of first row and so on.
89. What Do You Understand By Row-Major Order & Column-Major Order Of Arrays?
Answer: A two-dimensional array is declared like the way we declare a one-dimensional array except that we specify the number of elements in both dimensions. For example,
int grades[3][4];
The first bracket ([3]) tells the compiler that we are declaring 3 pointers, each pointing to an array. We are not talking about a pointer variable or pointer array. Instead, we are saying that each element of the first dimension of a two-dimensional array reference a corresponding second dimension. In this example, all the arrays pointed to by the first index are of the same size.
The second index can be of variable size. For example, the previous statement declares two-dimensional array where there are 3 elements in the first dimension and 4 elements in the second dimension.
Two-dimensional array is represented in memory in following two ways:
- Row major representation: To achieve this linear representation, the first row of the array is stored in the first memory locations reserved for the array, then the second row and so on.
- Column major representation: Here all the elements of the column are stored next to one another.
In row major representation, the address is calculated in a two dimensional array as per the following formula
The address of a[i] [j] =base (a) + (i*m+ j) * size
where base(a) is the address of a[0][0], m is second dimension of array a and size represent size of the data type.
Similarly, in a column major representation, the address of two-dimensional array is calculated as per the following formula
The address of a[i] [j] = base (a) + (j*n +i) * size
Where base (a) is the address of a [0] [0], n is the first dimension of array a and size represents the size of the data type.
90. What Is Meant By The Terms Row-Major Order & Column-Major Order?
Answer: Storing the array column by column is known as column-major order and storing the array row by row is known as row-major-order. The order used depends upon the programming language, not the user. For example, consider array A (3,4) and how this array will be stored in memory in both the cases is shown below
91. Can The Size Of An Array Be Declared At Runtime?
Answer: No, the size of an array can't be declared at run time, we always need to mention the dimensions of an array at the time of writing program i.e. before run time.
92. The Array DATA [10, 15] Is Stored In Memory In Row - Major Order. If Base Address Is 200 & Element Size Is 1. Calculate The Address Of Element DATA [7, 12].
Answer:
Base address = 200
Element Size = l
Address of element DATA [7,12] = 200+[(7-l)*15+(12-l)]*l
= 200+[6*15+11]
= 200+[90+11]=301
Address of DATA [7,12] = 301
Also Read The Following Questions:
56) What is a NULL Pointer? Whether it is same as an uninitialized pointer?
57) Are pointers integer?
58) What does the error āNull Pointer Assignmentā means and what causes this error?
59) What is generic pointer in C?
60) How pointer variables are initialized?
61) What is static memory allocation?
62) What is dynamic memory allocation?
63) What is the purpose of realloc?
64) What is pointer to a pointer?
65) What is an array of pointers?
...Return To C Questions INDEX.
...Return To C Programming INDEX.
... Return To HR Interview Index
Comments
Post a Comment
Please share your opinions and suggestions or your experience in the comments section. This way we can all help each other...
Experienced guys can share their resumes at admin@interview-made-easy.com