logo

Crowdly

Browser

Add to Chrome

An array definition consists of a declaration specifier, an identifier, a dimens...

✅ The verified answer to this question is available below. Our community-reviewed solutions help you understand the material better.

An array definition consists of a declaration specifier, an identifier, a dimension, followed by an optional comma-separated list of values enclosed in braces:

type-specifier name [ dimension ] = {initialization-list}opt;

can be any of the simple data types we've studied so far including signed and unsigned versions of charintlong, and floating-point types such as floatdouble, and long double except void. Later in the course we'll study about storage specifiers and type qualifiers and expand on the declaration specifier.

Square brackets surround dimension which specifies the number of elements in the array. dimension must be a constant integral expression, that is, it must be possible to evaluate the value of dimension at compile-time and the type of the expression must be integral. Note that the constant integral expression dimension must evaluate to a value greater than or equal to . Note that C99 introduced variable-length arrays which allows the dimension to be specified at run-time. The committee changed its mind and C11 makes variable-length arrays optional. But the big thing is that variable-length arrays have always been illegal in C++. Therefore, assume throughout this course and all assessments related to this course that variable-length arrays are illegal; and this is enforced during compilation by using GCC option -Werror=vla.

initialization-list sets array elements to specific values and is optional. The number of values in the initialization list may be less than dimension, but not more. dimension is optional if you include initialization-list and explicitly initialize all values.

Arrays are not first-class citizens: an array cannot be initialized with another array, nor can one array be assigned to another. To copy one array into another, each element must be copied in turn.

The only operations that can be performed directly on an array name are the application of the sizeof and address-of & operators. For sizeof operator, the result is the number of bytes occupied by the array. That is, if each element of the array is of type T and the array dimension is n, the result of the sizeof operator is equal to n times sizeof(T).

Does the following array definition compile?

int x[100];
100%
0%
More questions like this

Want instant access to all verified answers on distance3.sg.digipen.edu?

Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!

Browser

Add to Chrome