How do you declare a one-dimensional array of 10 integers in C?

Enhance your programming skills with the RECF Programming Test. Features flashcards and multiple choice questions with hints and explanations. Prepare for success!

Multiple Choice

How do you declare a one-dimensional array of 10 integers in C?

Explanation:
In C, to declare a one-dimensional array of 10 integers you write the type, the name, and the size in brackets: int data[10]; This creates space for 10 int elements, accessible as data[0] through data[9]. The size must be a constant expression, and the brackets after the name signal an array, not a function or something else. The other forms don’t follow C syntax: using parentheses (10) looks like a function declaration, there is no array keyword like array, and placing the declarator after the size (data[10] int) isn’t valid C.

In C, to declare a one-dimensional array of 10 integers you write the type, the name, and the size in brackets: int data[10]; This creates space for 10 int elements, accessible as data[0] through data[9]. The size must be a constant expression, and the brackets after the name signal an array, not a function or something else. The other forms don’t follow C syntax: using parentheses (10) looks like a function declaration, there is no array keyword like array, and placing the declarator after the size (data[10] int) isn’t valid C.

Subscribe

Get the latest from Passetra

You can unsubscribe at any time. Read our privacy policy