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

Discussion

Which of the following statements are correct about 6 used in the program?

int num[6];
num[6]=21;

  • A.In the first statement 6 specifies a particular element, whereas in the second statement it specifies a type.
  • B.In the first statement 6 specifies a array size, whereas in the second statement it specifies a particular element of array.
  • C.In the first statement 6 specifies a particular element, whereas in the second statement it specifies a array size.
  • D.In both the statement 6 specifies array size.

Answer: B

Correct answer: In the first statement 6 specifies a array size, whereas in the second statement it specifies a particular element of array.

In a declaration, int num[6];, the 6 is the size - how many elements to reserve. In an expression, num[6] = 21;, the 6 is a subscript naming one element. The same notation means different things in the two positions, and here the second use is in fact out of bounds: valid subscripts run 0 to 5.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.