Skip to main content

C Programming Interview Questions With Answers - Part XI.


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

Popular posts from this blog

Tell Me Something About Yourself - Interview Answers.

Try to introduce some of your most important employment-oriented skills as well as your education and accomplishments to the interviewer. Answer to this question is very important because it positions you for the rest of the interview . That's why this statement is often called the "Positioning Statement". One should take the opportunity to show his/her communication skills by speaking clearly and concisely in an organized manner. Since there is no right or wrong answer for this question hence it is important to appear friendly. YOUR ANSWERS CAN BE: 1) I am a person with strong interpersonal skills and have the ability to get along well with people . I enjoy challenges and looking for creative solutions to problems. 2) Besides the details given in my resume, I believe in character values, vision and action. I am quick in learning from mistakes. I am confident that the various tests that you have conducted will corroborate my competencies apti...

What Is (Are) Your Weakness (Weaknesses)? - Interview Answers

There’s a saying – “However small the thorn maybe it has the ability to pierce.” Never say you are a Workaholic, a Perfectionist, etc. because it sounds negative. Try to convert these negative biased qualities into positive ones. For Example, In   place of Workaholic you can say you are a hard worker and always willing to work for extra hours. In place of Perfectionist , you can say you are detail oriented and like to set high standard for work. “Try to specify your weakness as your strength and also highlight it as a benefit.” Your answers can be: 1) One of my weaknesses as I perceive is occasional compromise on time for quality and perfection. 2) I feel I am not very detail-oriented . I’m a person that wants accomplish as much as possible. I realized this hurts quality and therefore I‘m trying hard to find a balance between quality and quantity. 3) At times even when I need help, I try to solve my own problems instead of asking a co-worker who might know...

What Is (Are) Your Strengths? - Interview Answers

This is a simple and popular interview question. Generally people answer it in two ways. There are people who simply state their strength like “I am Young, Dynamic, Intelligent, Smart and so on…”. Such answer is neither right nor wrong but does not help u in any way also. Secondly there are peoples who state their strengths and explain them how he can use his strength for the job and industry. Do not simply state your strength. Everyone has some strength, all you need is to convert them into benefits. In short, try to advertise yourself by converting your features into strengths. “EVERYONE CLAIM THEY ARE HONEST, HARDWORKING, SMART AND SO ON….. BUT WITH AN EXAMPLE IT IS MUCH MORE BELIEVABLE.” Your answers can be : 1) I am a hard worker and because of this ability I can work for additional hours to accomplish my tasks.I am commitment oriented and hence I always enjoy the trust and confidence of my team mates which enables me to perform my duties very easily. 2) I am a...