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

Arrays Questions and Answers

101.

The  const  feature can be applied to

Answer: D

Correct answer: All of these

const can qualify an ordinary identifier (const int n = 10;), an array (const char msg[] = "hi";), and an array argument (void f(const int a[])). The last is the most useful of the three: it documents, and lets the compiler enforce, that the function will not modify the caller’s data.

Please log in or register to report this question.

Answer: B

Correct answer: Both A and B

A is true: every element of an array has the same type and the same storage class, which is what makes uniform address arithmetic possible. B is true: the number of subscripts is the dimension - a[3][4] is two-dimensional. The remaining option is false, since a subscript may perfectly well be zero; indeed index 0 is the first element.

Please log in or register to report this question.

103.

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.

104.

Consider the array definition

int num [10] =  {3, 3, 3};

Pick the Correct answers

Answer: A

Correct answer: num [9] is the last element of the array num

The array has 10 cells, so the last is num[9]. The initialiser supplies only three values, and when an array is partly initialised the remaining elements are set to zero. So num[0], num[1] and num[2] are 3, while num[3] and num[8] are both 0 - which is why the other two statements are false.

Please log in or register to report this question.

105.

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.

106.

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.

107.

The following program

main( )
{
static int a[ ] = { 7, 8, 9 } ;
printf( "%d", 2[ a ] + a[ 2 ] ) ;
}

 

Answer: D

a[2] will be converted to *(a + 2).
*(a + 2) can as well be written as *(2 + a ) .
 *(2 + a ) is nothing but 2 [a] . So. a [2] is essentially same as 2 [a] which is same as * ( 2 + a ). So. it prints 9 + 9 = 18. Some of the modem compilers don't accept 2[a].

Please log in or register to report this question.

108.

The parameter passing mechanism for an array is

Answer: C

Correct answer: call by reference

C passes everything by value, but what is passed for an array is its base address, so the function works on the caller’s own storage and any change it makes is visible afterwards. That effect is what “call by reference” describes, and it is why a function can fill an array supplied by its caller.

Please log in or register to report this question.

109.

Consider the statement

int val[2] [4] = { 1, 2, 3, 4, 5, 6, 7, 8} ;

4 will be the value of

Answer: A

Correct answer: val[0 ][ 3]

A brace-list without inner braces fills a two-dimensional array row by row. With 4 columns, the first row takes 1, 2, 3, 4 and the second 5, 6, 7, 8. The value 4 is therefore the fourth element of row 0, that is val[0][3]. val[0][4] is out of bounds, and val[1][1] is 6.

Please log in or register to report this question.

110.

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

Answer: D

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.

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