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

Arrays Questions and Answers

Answer: B

Correct answer: Collection of similar type of elements

An array is a collection of elements of the same type, stored consecutively and reached by index. The uniform element size is what makes the index arithmetic work; a collection of mixed types is a structure, not an array.

Please log in or register to report this question.

73.

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

Answer: D

Correct answer: Dope vector

The dope vector is the descriptor an implementation keeps for an array: base address, element size, number of dimensions and the bounds of each. It is what address computation and bounds checking work from. A symbol table holds compile-time names and types; an activation record holds one call’s locals.

Please log in or register to report this question.

74.

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: the address of the first element of the array

An array name decays to a pointer to its first element in almost every expression, which is why passing an array to a function passes only that address. The exceptions are the operands of sizeof and of the address-of operator.

Please log in or register to report this question.

76.

Pick the correct answers
if x is an one dimensional array, then

Answer: D

Correct answer: both (b) & (c)

(c) is the definition of subscripting: x[i] is *(x + i). (b) follows from it - &x[i] is x + i, so dereferencing it gives the same element back. (a) is false: &x[i] equals x + i, not x + i - 1, which would be the previous element.

Please log in or register to report this question.

77.

Are the expressions arr and &arr same for an array of 10 integers?

Answer: B

Correct answer: No

They hold the same address but they are not the same expression, because their types differ: arr is int * and &arr is int (*)[10]. The difference shows the moment you do arithmetic - arr+1 advances 4 bytes, &arr+1 advances 40.

Please log in or register to report this question.

78.

Predict the output of below code:

int main() 
{ 
    char a[2][3][3] = {'g','e','e','k','s','f','o', 
                           'r','g','e','e','k','s'}; 
    printf("%s ", **a); 
    getchar(); 
    return 0; 
} 

 

Answer: C

Correct answer: geeksforgeeks

a is char[2][3][3] - 18 bytes in one contiguous block. The 13 characters of the initialiser fill it in order and the remaining 5 bytes are set to zero, because a partly initialised array has the rest zero-filled. **a is the address of the first byte, and %s prints from there to the first NUL - which is byte 14. So the whole run of 13 characters comes out: geeksforgeeks.

Please log in or register to report this question.

79.

Let x be an array. Which of the following are illegal

Answer: A

Correct answer: x++

An array name is not a modifiable lvalue - it names fixed storage, so it cannot be assigned to or incremented, and x++ is rejected. x+1 is fine: the name decays to a pointer and pointer arithmetic gives the address of the second element. x[2] is ordinary subscripting.

Please log in or register to report this question.

Answer: A

Correct answer: All of the above

The size may be omitted 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 decays to a pointer and the size is meaningless. And in a declaration, extern int a[];, the definition elsewhere supplies the size.

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