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

Arrays Questions and Answers

91.

A pointer to a block of memory is effectively same as an array

Answer: A

Correct answer: True

An array name in an expression yields a pointer to its first element, and a[i] is defined as *(a + i). So once you have a pointer to a block of memory you can subscript it exactly as you would an array. The two differ in what they are - an array is storage, a pointer is a variable holding an address - but for reading and writing elements they behave the same.

Please log in or register to report this question.

92.

Which of the following statements are correct about an array?

1. The array int num[26]; can store 26 elements.

2. The expression num[1] designates the very first element in the array.

3. It is necessary to initialize the array at the time of declaration.

4. The declaration num[SIZE] is allowed if SIZE is a macro.

Answer: B

Correct answer: 1,4

1 is true - int num[26]; holds 26 elements, with subscripts 0 to 25. 4 is true - a macro expands before compilation, so num[SIZE] is a constant bound. 2 is false: num[1] is the second element, since indexing starts at 0. 3 is false: an array need not be initialised at declaration, though an uninitialised automatic array holds junk.

Please log in or register to report this question.

Answer: B

Correct answer: There are chances of wastage of memory space if elements inserted in an array are lesser than the allocated size

An array’s size is fixed when it is created, so if fewer elements are stored than were allocated, the unused cells are still occupied memory. That is the classic drawback, and it is what dynamic structures such as linked lists and growable lists exist to avoid. Stacks and queues can be built on arrays, indices are never negative, and elements are reached directly by index rather than sequentially.

Please log in or register to report this question.

Answer: A

Correct answer: All of these

The size may be omitted in all three cases: in a definition with an initialiser, where the compiler counts the initialisers; in a declaration such as extern int a[];, where the definition elsewhere supplies it; and in a formal parameter, where the array is adjusted to a pointer and any bound is ignored.

Please log in or register to report this question.

95.

Which of the following function is more appropriate for reading in a multi-word string?

Answer: C

Correct answer: gets()

gets() reads characters up to the newline, so it takes a whole line including the spaces between words. scanf("%s", ...) stops at the first whitespace and would read only the first word. printf and puts write rather than read. Note that gets() cannot limit the input length and has been removed from modern C for that reason; fgets() is what should be used in real code.

Please log in or register to report this question.

96.

If storage class is missing in the array definition, by default it will be taken to be

Answer: D

Correct answer: either automatic or external depending on the place of occurrence

With no storage class written, the default depends on where the definition appears. Inside a function it is auto - allocated on the stack, uninitialised, and gone when the function returns. At file scope it is external - allocated for the life of the program and zero-initialised.

Please log in or register to report this question.

97.

Consider the following type definition.

typedef char x[10];

x myArray[5];

What will sizeof(myArray)  be ? (Assume one character occupies 1 byte)

Answer: C

Correct answer: 50 bytes

The typedef makes x mean char[10]. So x myArray[5] is an array of 5 such arrays:

\[ 5 \times 10 \times 1 = 50 \text{ bytes} \]

A typedef of an array type is easy to misread, because the array-ness is hidden behind the name; expanding it back out is the reliable way to size it.

Please log in or register to report this question.

98.

The maximum number of dimension an array can have in C is

Answer: A

Correct answer: compiler dependent

The C standard sets no fixed maximum. It specifies only a minimum that a conforming implementation must support - historically 12 levels of array, pointer and function declarators - so the practical ceiling is whatever the compiler allows. In practice arrays of more than three or four dimensions are rare.

Please log in or register to report this question.

99.

While passing an array as an actual argument, the function call must have the array name

Answer: C

Correct answer: alone

The call passes the array name on its own - f(arr) - because the name already yields the base address. Brackets or a size in the call would be a syntax error; those belong in the function’s parameter list, not at the call site.

Please log in or register to report this question.

100.

Predict the output of below code: 

#include <stdio.h>
    int main()
    {
        int ary[2][3][4], j = 20;
        ary[0][0] = &j;
        printf("%d\n", *ary[0][0]);
    }

 

Answer: C

Correct answer: Compile time Error

ary[0][0] has type int[4] - a whole row of four ints, not a single element. An array is not a modifiable lvalue, so it cannot be assigned to, and the type on the right, int *, does not match in any case. The compiler rejects the assignment; ary[0][0][0] = j; would be the sensible statement.

Please log in or register to report this question.

Loading…

Other Subjects

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