Which of the following statements declares a one-dimensional Character array named item that consists of five elements?

”char
= “”;” option2=”char item[0 to 5] = “”;” option3=”char item[4] = “”;” option4=”char item[5] = “”; E. string item[5] = ‘ ‘;” correct=”option1″]

The correct answer is: A. char item[0 to 4] = “”;

A character array is a data structure that stores a sequence of characters. The elements of a character array are accessed using subscripts, which start at 0. The statement char item[0 to 4] = ""; declares a character array named item that consists of five elements, from item[0] to item[4]. The elements of the array are initialized to the empty string.

The statement char item[0 to 5] = ""; is incorrect because it declares an array with six elements, from item[0] to item[5]. The statement char item[4] = ""; is incorrect because it declares an array with only one element, item[4]. The statement char item[5] = ""; is incorrect because it declares an array with five elements, but the elements are not initialized. The statement string item[5] = ' '; is incorrect because it declares a string array, not a character array.

Exit mobile version