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...

Sample Cover Letter / Job Application.

To The General Manager (HR) [ Name and Designation (Bold Words)] Infosys Limited Delhi ā€“ 110001 Uttam Agrawal Gandhi Chowk, Bhartee Street [ Name Bhawanipatna, Kalahandi Contact Address Orissa ā€“ 766001 Telephone No.] Ph. no - +91-9438170446 [Sub: Application for the position of ___________ in your esteemed organization.] Respected Sir, (Always use ā€˜Respectedā€™) With reference to your advertisement dated 14th mayā€™ 08 in The Times of India for the position of ___________ . I would like to place myself as a strong contender before you. OR This has reference to your advertisement dated 14th mayā€™ 08 in The Times of India for the position of ____________. In the said connection I take this opportunity to apply for the said position as a strong contender. /*This is the Introduction i.e the first paragraph of your application/* ( Now the Second Paragraph is the Self Introduction) Try to start the second paragraph with the below mentioned lines: - I have the p...

HR Interview Questions With Simple Answers - Top 30.

Here are some very important HR questions which are often asked during Interviews and I believe these answers can really help you to get through....... Click on them to view the answer: 1) Tell Me Something About Yourself ? 2) What Are Your Strengths? 3) What Are Your Weaknesses? 4) How Do You Handle Pressure / Can You Work Well Under Pressure? 5) What Are Your Short Term Goals? 6) What Are Your Long Term Goals? 7) Where Do You See After 5 Years? 8) Why Should We Hire You? 9) What Is Your Salary Expectation? 10) Why Do You Want To Leave Your Current Job? 11) Do You Prefer To Work Alone Or As A Team Player? 12) What Made You Choose Your Major / Stream? 13) Why Didnā€™t You Pursue A Career In Your Major / Stream? 14) Why Do You Want To Work For Us? 15) Are You Willing To Travel? 16) Are You Willing To Take Risks? 17) What Do You Know About This Company? 18) What Do You Seek From A Job? 19) How Do You Evaluate Success? 20) Dur...