Home » C and C++, Tech Corner

Arrays

24 July 2009 No Comments Posted By:Dileep
  • A programming language construct which stores and organizes a set of data items is called a data structure.
  • There are different types of data structures – arrays, stacks, queues, linked lists, structures, trees, files, etc.
  • An array can be defined as an ordered list of homogeneous data elements.
  • These elements may be of type int, float, char or double.
  • All these elemets are stored in consecutive memory locations.
  • An array is described by a single name or an identifier.
  • And each element in an array is referenced by a subscript(or an index) enclosed in a pair of square brackets.
  • The subscript indicates the position of an individual data item in an array.
  • The subscipt must be an unsigned positive integer.
  • Because of these subscripts, sometimes an array is called as a subscripted variable.


  • Arrays classified into – one-dimensional array and multi-dimensional arrays.
  • The dimensionality of an array is determined by the number of subscripts present in the given array.
  • An array must be declared before it appears in a C program. At the same time, the size of an array must be specified.
  • One-dimensional array – This is a linear list of a fixed number of data items of the same type.
  • Similar to a row or a coloumn matrix.
  • Also called a single-dimensional array or a one-subscripted variable.
  • Syntax – data-type arrayname[size];
  • Subscript must be an unsigned positive integer constatnt or an expression.
  • Subscript of subscript is not allowed.
  • C does not perform bounds checking for an array.
  • In C, the subscript value ranges from 0 to one less than the maximum size.
  • The total amount of memory that can be allocated to a one-dimensional array is computed as -

Total size = size * [sizeof(data_type)];

  • Initialization of a one-dimensional aray

Syntax – data_type array_name[size] = {element1,element2,…,elementn};

  • Multi-dimensional arrays – If the number of subscripts is more than one then such arrays are called multi-dimensional arrays.
  • Two-dimensional(2-D) array, three-dimensional(3-D) array, and so on.
  • Two-dimensional array – It is an ordered table of homogeneous elements.
  • Generally referred to a matrix of some rows and some coloumns.
  • Also called a two-subscripted variable.
  • Syntax – data_type array_name[rows][coloumns];
  • Row-major order and Coloumn-major order.
  • Initialization of a two-dimensional array

Syntax – data_type array_name[size1][size2]={e1,e2,…,en};

<<Previous Post

Next Post>>

Related posts:

  1. Pointers
  2. Structures and Unions
  3. Strings(Character Arays)
  4. Constants and Variables
  5. Functions

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>