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

Arrays Questions and Answers

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.

82.

What will be the output of the program if the array begins at 65472 and each integer occupies 2 bytes?

#include <stdio.h>

int main()
{
    int a[3][4] = {1, 2, 3, 4, 4, 3, 2, 1, 7, 8, 9, 0};
    printf("%u, %u\n", a+1, &a+1);
    return 0;
}

 

Answer: B

Correct answer: 65480, 65496

a is a 3×4 array of 2-byte ints. a alone decays to a pointer to its first row, so adding 1 skips one row of 4 ints:

\[ 65472 + 4 \times 2 = 65480 \]

&a is a pointer to the whole array, so adding 1 skips all 12 ints:

\[ 65472 + 12 \times 2 = 65496 \]

Same address, different type - and the type is what decides how far +1 moves.

Please log in or register to report this question.

83.

What will be the output of the program if the array begins 1200 in memory?

#include <stdio.h>

int main()
{
    int arr[]={2, 3, 4, 1, 6};
    printf("%u, %u, %u\n", arr, &arr[0], &arr);
    return 0;
}

 

Answer: B

Correct answer: 1200, 1200, 1200

All three expressions denote the same address, the start of the array: arr decays to &arr[0], &arr[0] is that address written out, and &arr is the address of the whole array, which begins at the same byte. Only their types differ, so all three print 1200.

Please log in or register to report this question.

84.

Does this mentioning array name gives the base address in all the contexts?

Answer: B

Correct answer: No

Not in all contexts. Two operators take the array as a whole rather than letting it decay: sizeof(arr) gives the size of the entire array, and &arr yields a pointer to the array rather than to its first element. Everywhere else the name does give the base address.

Please log in or register to report this question.

Answer: D

Correct answer: All of these

All three are true of C. Constant expressions such as 2*60*60 are folded at compile time. Adjacent string literals are concatenated by the compiler, so "abc" "def" becomes one string. And the size of an array must be known when the code is compiled, which is why the bound has to be a constant expression rather than a variable.

Please log in or register to report this question.

86.

What will be the address of the arr[2][3] if arr is a 2-D long array of 4 rows and 5 columns and starting address of the array is 2000?

Answer: C

Correct answer: 2052

With 5 columns and 4 bytes per element, row-major gives

\[ 2000 + 4\,(2 \times 5 + 3) = 2000 + 4 \times 13 = 2052 \]

The row count, 4, does not enter the calculation - only the number of columns matters, because that is how far one row-step moves you.

Please log in or register to report this question.

87.

Which of the following is a correct way to declare a multidimensional array in Java?

Answer: C

Correct answer: int[][]arr;

A second dimension is added by a second pair of empty brackets: int[][] arr;. Java has no [[]] form; a two-dimensional array is really an array whose elements are themselves arrays, which is why the brackets come in separate pairs.

Please log in or register to report this question.

88.

A one dimensional array A has indices 1....75. Each element is a string and takes up three memory words. The array is stored starting at location 1120 decimal. The starting address of A[49] is

Answer: C

Correct answer: 1264

The indices start at 1, so A[49] has 48 elements before it, each of 3 words:

\[ 1120 + 3 \times (49 - 1) = 1120 + 144 = 1264 \]

Treating the array as 0-based would give 1267 - the distractor the question is testing for.

Please log in or register to report this question.

89.

Predict the output of below code:

#include <stdio.h>

int main()
{
    int a[5] = {5, 1, 15, 20, 25};
    int i, j, m;
    i = ++a[1];
    j = a[1]++;
    m = a[i++];
    printf("%d, %d, %d", i, j, m);
    return 0;
}

 

Answer: B

Correct answer: 3, 2, 15

Starting from a = {5, 1, 15, 20, 25}:

  1. i = ++a[1]; - pre-increment, so a[1] becomes 2 and i = 2.
  2. j = a[1]++; - post-increment, so j = 2 (the old value) and a[1] becomes 3.
  3. m = a[i++]; - the subscript is the old i, so m = a[2] = 15, and i becomes 3.

Printed: 3, 2, 15.

Please log in or register to report this question.

90.

In which of the following cases, linked list implementation of sparse matrices consumes the same memory space as the conventional way of storing the entire array?

Answer: C

Conventional way needs storage of m x n
In the case of linked list implementation of sparse matrices, storage needed will be(the number of non-zero entries).
Only in case(c), both the methods need the same storage of 30.

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