Question

Is array a data type in c ? If yes can we create variables of array type as in structures, enum .

 int arr[10] ;//is this arr is a data type of 10 ints
Was it helpful?

Solution 2

Arrays are a derived type, if we look at the C99 draft standard section 6.2.5 Types paragraph 20 says(emphasis mine):

Any number of derived types can be constructed from the object, function, and incomplete types, as follows:

An array type describes a contiguously allocated nonempty set of objects with a particular member object type, called the element type.36) Array types are characterized by their element type and by the number of elements in the array. An array type is said to be derived from its element type, and if its element type is T, the array type is sometimes called ‘‘array of T’’. The construction of an array type from an element type is called ‘‘array type derivation’’.

You can create arrays of structures and enums, the only exception is noted in footnote 36:

Since object types do not include incomplete types, an array of incomplete type cannot be constructed.

OTHER TIPS

Is array a data type in C?

"Array" with no further specification is not a separate data type, but once you specify its size and its element type, it becomes a data type. In other words, you cannot define a type that takes "an array of anything" or "an array of a specific type without a specific size", but you can define a data type that is an array of N items of type T.

If yes can we create variables of array type as in structs, enum?

int arr[10] ;//is this arr is a data type of 10 ints

Yes, it is. You can tell by examining sizeof(arr): it will be ten times the sizeof(int).

Sure, an array of a data type is another data type.

You could do something like:

typedef int intarr3_t[3];

intarr3_t intarr = {1, 2, 3};

yes is it an data type and yes you can make a number of them.

To make it clearer, you can make a typedef of an array.

typedef char MyType_t [10];

Will make MyType_t an array of 10 chars:

MyType arrayOfTenChars;

The concept of an array relates to a derived type. Then there are data types such as array of int and array of 10 ints.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top