meljun cortes c++ array

22
C++ C++ ARRAY ARRAY MELJUN CORTES MELJUN CORTES

Upload: meljun-cortes

Post on 16-Jul-2015

64 views

Category:

Technology


1 download

TRANSCRIPT

C++C++ARRAYARRAY

MELJUN CORTESMELJUN CORTES

MELJUN CORTES, MBA,MPA,BSCSMELJUN CORTES, MBA,MPA,BSCS

ARRAYARRAY

a series of elements of the same type placed in contiguous memory locations that can be individually referenced by adding an index to a unique identifier.

A sequence of objects all of which have the same type. The objects are called the elements of the array and are numbered consecutively 0, 1, 2, 3, etc. These numbers are called the index values or subscripts. Subscripts locate the element's position within an array, thereby giving direct access into the array.

MELJUN CORTES, MBA,MPA,BSCSMELJUN CORTES, MBA,MPA,BSCS

DECLARATION OF AN ARRAYDECLARATION OF AN ARRAY

Like a regular variable, an array must be declared before it is used. A typical declaration for an array in Visual C++ is:

type name [elements];

type is a valid type (like int, float...) name is a valid identifier elements field (which is always enclosed in

square brackets []), specifies how many of these elements the array has to contain.

MELJUN CORTES, MBA,MPA,BSCSMELJUN CORTES, MBA,MPA,BSCS

PROCESSING ARRAYSPROCESSING ARRAYS

An array is a composite object. It is composed of several elements with independent values. In contrast, an ordinary variable of a primitive type is called a scalar object.

MELJUN CORTES, MBA,MPA,BSCSMELJUN CORTES, MBA,MPA,BSCS

MELJUN CORTES, MBA,MPA,BSCSMELJUN CORTES, MBA,MPA,BSCS

INITIALIZING AN ARRAYINITIALIZING AN ARRAY

When an initialization of values is provided for an array, Visual C++ allows the possibility of leaving the square brackets empty [ ]. In this case, the compiler will assume a size for the array that matches the number of values included between braces { }:

0 1 2 3 4

array 10 20 30 40 50

MELJUN CORTES, MBA,MPA,BSCSMELJUN CORTES, MBA,MPA,BSCS

MELJUN CORTES, MBA,MPA,BSCSMELJUN CORTES, MBA,MPA,BSCS

MELJUN CORTES, MBA,MPA,BSCSMELJUN CORTES, MBA,MPA,BSCS

MELJUN CORTES, MBA,MPA,BSCSMELJUN CORTES, MBA,MPA,BSCS

MELJUN CORTES, MBA,MPA,BSCSMELJUN CORTES, MBA,MPA,BSCS

MELJUN CORTES, MBA,MPA,BSCSMELJUN CORTES, MBA,MPA,BSCS

MELJUN CORTES, MBA,MPA,BSCSMELJUN CORTES, MBA,MPA,BSCS

PASSING ARRAYS AS ARGUMENTS PASSING ARRAYS AS ARGUMENTS TO FUNCTIONS TO FUNCTIONS

MELJUN CORTES, MBA,MPA,BSCSMELJUN CORTES, MBA,MPA,BSCS

MULTIDIMENSIONAL ARRAYSMULTIDIMENSIONAL ARRAYS

Multidimensional arrays can be described as "arrays of arrays". For example, a bidimensional array can be imagined as a bidimensional table made of elements, all of them of a same uniform data type.

MELJUN CORTES, MBA,MPA,BSCSMELJUN CORTES, MBA,MPA,BSCS

TWO DIMENSIONAL ARRAYTWO DIMENSIONAL ARRAYAlso referred to as a table, a two dimensional array has two indexes. The first index refers to the row, while the second refers to column. The syntax in declaring two-dimensional arrays in Visual C++ is:

<data type> <array name> [ <row size> ] [<column size>]<data type> <array name> [ <row size> ] [<column size>]

In a two-dimensional array, the array elements are arranged in row-major order.

MELJUN CORTES, MBA,MPA,BSCSMELJUN CORTES, MBA,MPA,BSCS

MELJUN CORTES, MBA,MPA,BSCSMELJUN CORTES, MBA,MPA,BSCS

MELJUN CORTES, MBA,MPA,BSCSMELJUN CORTES, MBA,MPA,BSCS

MELJUN CORTES, MBA,MPA,BSCSMELJUN CORTES, MBA,MPA,BSCS

PASSING TWO-DIMENSIONAL PASSING TWO-DIMENSIONAL ARRAYS TO FUNCTIONS ARRAYS TO FUNCTIONS

MELJUN CORTES, MBA,MPA,BSCSMELJUN CORTES, MBA,MPA,BSCS

THREE DIMENSIONAL ARRAYTHREE DIMENSIONAL ARRAYA three dimensional array has three indexes. The first index refers to the dimension, second index refers to the row, while the third index refers to column. The syntax in declaring three dimensional arrays in Visual C++ is:

<data type> <array name> [ <dimension size >] <data type> <array name> [ <dimension size >] [<row size> ] [<column size>][<row size> ] [<column size>]

MELJUN CORTES, MBA,MPA,BSCSMELJUN CORTES, MBA,MPA,BSCS

MELJUN CORTES, MBA,MPA,BSCSMELJUN CORTES, MBA,MPA,BSCS