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

Arrays Questions and Answers

Answer: D

Correct answer: All of the above

All three reasons hold. A file persists after the program that wrote it ends, while an array vanishes with the process. A file need not be sized in advance, so no space is reserved and wasted. And the operating system provides tools - copy, search, sort, back up - that work on files and not on a program’s memory.

Please log in or register to report this question.

12.

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

Answer: C

Correct answer: Dope Vector

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

Please log in or register to report this question.

13.

What is the syntax for accessing the element at index 7 of an array a?

Answer: D

Correct answer: a[7]

C uses square brackets for subscripting, so the element at index 7 is a[7]. Braces are for initialiser lists, parentheses would be read as a function call, and quotes make a string literal. Note that a[7] is the eighth element, since indexing starts at 0.

Please log in or register to report this question.

14.

If x is an array of integers, then the value of &x[i] is same as

Answer: A

Correct answer: x+i

By definition x[i] is *(x + i), so taking the address of both sides gives &x[i] == x + i. The scaling is already built into pointer arithmetic: adding 1 to an int * advances by sizeof(int) bytes. That is why the two options that multiply or add sizeof(int) explicitly are wrong - they would scale twice.

Please log in or register to report this question.

15.

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

Answer: A

Correct answer: 1264

Indices start at 1 here, not 0, so \(A[49]\) is the 49th element and 48 elements precede it. Each takes 3 words:

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

Forgetting the 1-based start gives 1267, which is the distractor.

Please log in or register to report this question.

16.

In C, if you pass an array as an argument to a function, what actually gets passed?

Answer: C

Correct answer: Base address of the array

An array argument decays to a pointer to its first element, so what the function receives is the base address, not a copy of the elements. This is why passing a large array costs nothing extra, why the function can modify the caller’s data, and why sizeof inside the function returns the size of a pointer rather than of the array.

Please log in or register to report this question.

17.

Under which of the following conditions, the size of an one-dimensional array need not be specified?

Answer: D

Correct answer: All of the above

All three permit the size to be left out. With an initialiser the compiler counts the values. In a declaration such as extern int a[]; the size comes from the definition elsewhere. And as a formal parameter the array is adjusted to a pointer, so no bound is needed - nor at the call site, where the name is passed alone.

Please log in or register to report this question.

18.

Predict the output of the code below, if the array begins at address 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: C

Correct answer: 65480, 65496

a is a 3×4 array of 2-byte ints. a decays to a pointer to its first row, so a+1 steps over 4 ints:

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

&a is a pointer to the whole array, so &a+1 steps over all 12:

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

Please log in or register to report this question.

Answer: D

Correct answer: Both (a) and (b)

(a) is true: C really has only one-dimensional arrays - int a[3][4] is an array of 3 objects, each of type int[4]. (b) says the same thing from the other side: an element may itself be an array. The third statement is false; elements are always contiguous, which is exactly what makes subscripting work.

Please log in or register to report this question.

20.

If S is an array of 80 characters, then the value assigned to S through the statement scanf("%s",S) with input 12345 would be

Answer: A

Correct answer: "12345"

%s reads a whitespace-delimited sequence of characters and stores them followed by a null, without interpreting them. The digits 12345 are just five characters here, so S holds the string "12345". Note that S is passed without &, because an array name already yields its base address.

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