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

Arrays Questions and Answers

Answer: B

Correct answer: Container of objects of similar types

An array is a container holding a fixed number of values of a single type, laid out in consecutive memory. A hierarchy describes a tree, not an array; an array’s elements can be reassigned after initialisation, so it is not immutable; and it is very much a data structure - the most basic one there is.

Please log in or register to report this question.

Answer: B

Correct answer: what is assigned is compiler-dependent

The statement a[++n] = n++; both reads and modifies n twice between sequence points, and it uses the value of n on the right while also changing it on the left. The standard leaves the order unspecified, so the compiler may evaluate the subscript before or after the right-hand side. The result is undefined behaviour - what is assigned, and where, depends on the compiler.

Please log in or register to report this question.

43.

What will be the output of the program ?

#include <stdio.h>

int main()
{
    float arr[] = {12.4, 2.3, 4.5, 6.7};
    printf("%d\n", sizeof(arr)/sizeof(arr[0]));
    return 0;
}

 

Answer: B

Correct answer: 4

This is the standard idiom for the length of an array:

\[ \frac{\text{sizeof(arr)}}{\text{sizeof(arr[0])}} = \frac{4 \times 4}{4} = 4 \]

It works whatever the element type, because the element size divides out. It works only where the array itself is visible - inside a function that received it as a parameter, sizeof would give the size of a pointer.

Please log in or register to report this question.

44.

Array can be considered as set of elements stored in consecutive memory locations but having __________.

Answer: A

Correct answer: Same data type

The two defining properties of an array are that its elements lie in consecutive memory locations and that they are all of the same data type. The second follows from the first: address arithmetic can only step through the array if every element occupies the same number of bytes.

Please log in or register to report this question.

45.

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

Answer: A

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.

46.

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.

Answer: A

Correct answer: Base address is the address of 0th index element.

The base address of an array is simply where its first element sits - the address of the element at index 0. Every subscript is computed from it: a[i] lives at \(\text{base} + i \times \text{sizeof(element)}\), which is why index 0 costs no offset at all.

Please log in or register to report this question.

Answer: D

Correct answer: Easier to store elements of same data type

The advantage of an array is exactly that it stores many values of one type under one name, reached by index, which makes iterating and computing over them straightforward. The other options are false: an array holds one type, its elements can certainly be sorted, and its first index is 0.

Please log in or register to report this question.

Answer: C

Correct answer: int arr[3] = {1,2,3};

C uses square brackets for the dimension and braces for the initialiser list: int arr[3] = {1,2,3};. Parentheses in either position are a syntax error - arr(3) would be read as a function call, and (1,2,3) as a comma expression, not a list of initialisers.

Please log in or register to report this question.

50.

Consider the declaration

char street[10] = "abcdefghi";

Choose the correct remark(s)

Answer: D

Correct answer: None of the above

All three remarks are false.

  • &street and street hold the same address - the start of the array - and differ only in type.
  • &street is perfectly meaningful: it has type char (*)[10].
  • Because of that type, &street + 1 advances 10 bytes while street + 1 advances 1, so the two differ.

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