Skip to study material

Unit IV · Viva Questions

Revise the concepts orally. Open the study answer for a detailed explanation.

← Unit IV questions

Define an array and explain its advantages and limitations.

Do array elements have different types within one ordinary array?
No. They all have the declared element type.
Is the last valid index equal to the length?
No. It is one less than the length.
Study this concept →

Explain array declaration and initialisation with examples.

Can the compiler infer the size from a complete initialiser list?
Yes, as in int a[] = {1, 2, 3};.
Does int a[5]; initialise every ordinary automatic element to zero?
No. Give the elements valid values before reading them.
Study this concept →

Explain array subscripts, valid bounds and off-by-one errors.

What is an off-by-one error?
A boundary is one position too early or too late, often adding or missing one iteration.
Can an invalid subscript be assumed to return garbage safely?
No. The behaviour is undefined.
Study this concept →

Write a C program to read and display an array using loops.

Why is & used with a[i] in scanf?
scanf needs the address of the int object into which it stores input.
Does displaying an array change its order?
No. This program only reads its stored elements.
Study this concept →

Explain array traversal and write a program to find the sum of its elements.

Must an array be sorted before summing it?
No.
What changes when traversal runs backwards?
The visiting order changes; the same elements can still be processed.
Study this concept →

Write a C program to find minimum, maximum and average in an integer array.

Can this algorithm handle duplicate extremes?
Yes. Equal copies do not change the extreme value.
Why reject n = 0?
There is no first element, and the average would require division by zero.
Study this concept →

Explain passing individual array elements as function arguments.

What value does a[1] identify in a zero-based array?
The second element.
Can passing an element’s address change that original element?
Yes, if a suitable function assigns through a valid pointer to it.
Study this concept →

Explain passing a one-dimensional array to a function with its length.

Does passing an array expression copy every element?
No. The argument normally supplies a pointer to its first element.
What does const protect in this parameter?
It prevents modifying elements through that const-qualified access.
Study this concept →

Compare linear search and binary search.

Can binary search use the middle element without sorted order?
The midpoint can be read, but the half-discarding logic would not be justified.
Do both iterative searches need another array?
No. Both can use O(1) auxiliary space.
Study this concept →

Explain bubble sort and write a C program to sort integers in ascending order.

Why does the inner limit shrink after every pass?
The rightmost values already fixed by earlier passes no longer need comparison.
What makes the best case linear in this version?
A no-swap pass triggers early termination.
Study this concept →

Explain selection sort and write a C program for ascending order.

Does selection sort avoid comparisons on sorted input?
No. This version still scans the remaining values each pass.
How can its order be changed to descending?
Select the maximum instead of the minimum for each next position.
Study this concept →

Explain insertion sort and write a C program for ascending order.

Why test j >= 0 before accessing a[j]?
To avoid reading outside the array; && evaluates its right side only if the left is true.
Why is the key stored before shifting?
Its original position can be overwritten during the shifts.
Study this concept →

Compare bubble sort, selection sort and insertion sort.

Does in-place sorting mean the original order is preserved?
No. In-place describes extra storage; stability describes equal-key order.
Which shown method always makes quadratic comparison scans?
Selection sort.
Study this concept →

Explain the declaration, initialisation and access of two-dimensional arrays.

What does row-major mean?
Elements of one row are contiguous, and rows follow one another.
Is int a[2][3] the same type as int **?
No.
Study this concept →

Write a C program using a function to add two matrices.

Can a 2 × 3 matrix be added to a 3 × 2 matrix?
No. Both dimensions must match.
Does matrix addition require a third nested loop?
No. One row loop and one column loop are enough.
Study this concept →

Write a C program using a function to multiply two matrices.

Why is C[i][j] initialised to zero?
Its inner loop must accumulate only the products for that result position.
Is A × B generally equal to B × A?
No.
Study this concept →

Explain the declaration and access of multidimensional arrays.

Which index changes fastest in C’s element storage order?
The rightmost index.
Can one index exceed its own bound because other storage follows?
No. Each indexed array access must remain valid.
Study this concept →

Explain how a two-dimensional array is passed to a function.

Can the first dimension be omitted in the shown parameter?
Yes. The parameter adjusts to a pointer to a row.
Does changing a logical column count change the actual row width?
No. The row width comes from the actual array type.
Study this concept →