Open main menu

Wikibooks β


C Programming/Types

854 bytes removed, 14 years ago
Moving Array Info to the Array Slot
== Complex data types ==
Arrays could be considered an extension of an existing variable's type: arrays cannot exist as a type on their own but act just to extend an existing variable. An array applied to a variable implies not a single variable but a series of variables of a single type indexed by integers starting from zero. The characters used to indicate an array are '[<var>x</var>]' where '<var>x</var>' is the number of variables in the series. For example, a single integer variable would be defined by <tt>int</tt>, but an array (series) of seven integer variables could be defined by <tt>int[7]</tt>. Assuming this variable had the name <var>a</var>, the individual integer variables could be accessed as <tt>a[0]</tt>, <tt>a[1]</tt>, <tt>a[2]</tt> and so on until <tt>a[6]</tt>. The integer used to index the series of variables is also known as a ''subscript''.
Structs, or data structures link multiple kinds of data into one data type such that the original members can be accessed by a the struct identifier followed by a '.' or a member operator and then followed by the identifier of the member variable you want to access. The member variables of a struct can be of any data type and can even be an array.