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

24.9-48.3 48.6-11.4 42.9-11.4 132.3-11.4 132.3s0 89.4 11.4 132.3c6.3 23.7 24.8 41.5 48.3 47.8C117.2 448 288 448 288 448s170.8 0 213.4-11.5c23.5-6.3 42-24.2 48.3-47.8 11.4-42.9 11.4-132.3 11.4-132.3s0-89.4-11.4-132.3zm-317.5 213.5V175.2l142.7 81.2-142.7 81.2z"/> Subscribe on YouTube
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