Machine-translated by Google. Questions are authored in English.
Top

Arrays Questions and Answers

121.

Which of the following statements mentioning the name of the array does NOT yield the base address?

1. When array name is used with the sizeof operator.

2. When array name is operand of the & operator.

3. When array name is passed to scanf() function.

4. When array name is passed to printf() function.

Answer: B

Correct answer: 1, 2

The name of an array normally decays to the address of its first element - which is why passing it to scanf() or printf() gives the base address. There are two exceptions. With sizeof the name means the whole array, so sizeof(arr) gives the total number of bytes. With & it again means the whole array, so &arr has type “pointer to array”. Those are statements 1 and 2.

Please log in or register to report this question.

122.

Minimum number of interchanges needed to convert the array 89,19,40,14,17,12,10,2,5,7,11,6,9,70, into a heap with the maximum element at the root is

Answer: B

Correct answer: 2

Build the max-heap bottom-up, checking each internal node from the last one back to the root. Numbering the array from 1:

1:89  2:19  3:40  4:14  5:17  6:12  7:10  8:2  9:5  10:7  11:11  12:6  13:9  14:70

  • Node 7 holds 10 with the single child 70 - swap. Node 7 now holds 70.
  • Nodes 6, 5 and 4 already dominate their children (12 over 6 and 9; 17 over 7 and 11; 14 over 2 and 5).
  • Node 3 holds 40 with children 12 and 70 - swap with 70. The 40 that sinks to node 7 still beats its only child, 10.
  • Node 2 (19 over 14 and 17) and the root (89 over 19 and 70) are already correct.

That is 2 interchanges in all.

Please log in or register to report this question.

Answer: B

Correct answer: All the above

The size may be left out in all three cases. In a definition with an initialiser, int a[] = {1,2,3};, the compiler counts the initialisers. In a formal parameter, void f(int a[]), the array is adjusted to a pointer and any bound is ignored. In a declaration, extern int a[];, the definition elsewhere supplies the size.

Please log in or register to report this question.

124.

The information about an array used in a program will be stored in

Answer: B

Correct answer: Dope vector

A dope vector is the run-time descriptor of an array: base address, element size, number of dimensions and the bounds of each. It is what makes address computation, and bounds checking in languages that do it, possible. A symbol table is a compile-time structure of names and types; an activation record holds one call’s local storage.

Please log in or register to report this question.

Loading…
Tags: Arrays Questions and Answers || Arrays MCQ Questions and Answers || Arrays GK Questions and Answers || Arrays GK MCQ Questions || Arrays Multiple Choice Questions and Answers || Arrays GK || GK on Arrays || C Programming Questions and Answers || C Programming MCQ Questions and Answers || C Programming GK Questions and Answers || GK on C Programming