33.4k views
1 vote
Which of the following correctly declares and initializes alpha to be an array of four rows and three columns with the component type int?

a. int alpha[4][3] = {{0, 1, 2} {1, 2, 3} {2, 3, 4} {5, 6, 7}};
b. int alpha[4][3] = {{0, 1, 2}, {1, 2, 3}, {2, 3, 4}, {5, 6, 7}};
c. int alpha[4][3] = {0, 1, 2; 1, 2, 3; 2, 3, 4; 5, 6, 7};
d. int alpha[4][3] = {0, 1, 2: 1, 2, 3: 2, 3, 4: 5, 6, 7};

1 Answer

7 votes

Final answer:

Option 'b' correctly declares and initializes a two-dimensional int array named alpha with four rows and three columns, filled with the respective values within curly braces.

Step-by-step explanation:

Of the options provided, option 'b' correctly declares and initializes alpha to be an array of four rows and three columns with the component type int:

int alpha[4][3] = {{0, 1, 2}, {1, 2, 3}, {2, 3, 4}, {5, 6, 7}};

The correct way to declare and initialize the array alpha with four rows and three columns with the component type int is option b. The correct syntax is: int alpha[4][3] = {{0, 1, 2}, {1, 2, 3}, {2, 3, 4}, {5, 6, 7}};

This statement creates a two-dimensional array in C programming language with the specified size, and initializes the elements within the curly braces {}. Each inner brace initializes the elements of a row, and the commas between the inner braces separate each row.

User Atilio Jobson
by
7.7k points