INTRODUCTION OF ARRAY
Aaary
is collection of homogenous data type. An array is defined as a
sequence of object of the same data type. All the elements of an
array are either of type int (Whole numbers) , or all of them are of
type char, or all of them are of floating decimal point type,etc.
An
array connot have a mixture of different data types as its element.
In computer memory ,array elements are store in a sequence of
adjacent memory blocks.
The
declaration of array includes the type of array that is the type of
value we are going to store in it, the array name and maximum number
of elements.
Examples:
short
val [200];
val
[12] = 5;
Declaration
& Data Types:
Arrays
have the same data types as variables, i.e., short, long, float etc.
They are similar to variables: they can either be declared global or
local.
They are declared by the given syntax:
Datatype
array_name [dimensions] = {element1,element2,….,element}
The
declaration form of one-dimensional array is:
Data_type
array_name [size];
The
following declares an array called ‘numbers’ to hold 5 integers
and sets the first and last elements. C arrays are always
TYPES
OF ARRAY
One-Dimensional
Array:
One
Dimensional array
are same as those used variable names. Every array given same name.
The declaration of one-dimensional array takes the following form:
Array
_type array_name[array_size];
We
can declare arrays of any built-in type such as char, float, unsigned
int, etc. In addition, we can declare arrays of user-defined types
such as structures, enumerated data
types,
etc. Note the can declare one or more arrays in a single declaration
statement. We can also mix scalar variables and arrays in a
declaration statement.
Syntax:-
Int a[]={};
Or
Int[] a={};
Or
Int a[] = new int a[]
Two-Dimensional
Array:
A
two-dimensional
array (commonly
called a matrix)
consists
of elements of the same type arranged in rows and columns. The rows
and columns of a matrix are numbered starting from 0. Thus, for an
array of size rows
x
cols,
the
row subscripts are in the range 0 to rows
- 1
and the column subscripts are in the range 0 to cols
– 1.
Syntax:-
Array_type
arrry_name [rows] [cols];
0 comments:
Post a Comment