Array is collection of more than one data at same location of same type.
Syntax:
data type name[size];
This will create memory of specified size -data.
For example, an array containing 4 integer values of type
int rn[4];
In array memory always start from 0.
By default, regular arrays of local scope (for example, those
declared within a function) are left uninitialized. This means that none of
its elements are set to any particular value; their contents are
undetermined at the point the array is declared.
But the elements in an array can be explicitly initialized to specific values when it is declared, by enclosing those initial values in braces {}. For example:
Call us @ 98256 18292.
Visit us @ http://tccicomputercoaching.com/
Syntax:
data type name[size];
This will create memory of specified size -data.
For example, an array containing 4 integer values of type
int
called rn
could be represented as:
int rn[4];
3
|
2
|
1
|
0
|
In array memory always start from 0.
Initializing arrays
But the elements in an array can be explicitly initialized to specific values when it is declared, by enclosing those initial values in braces {}. For example:
|
int
|
Accessing the values of an array
marks[2] = 75;
EXAMPLE
#include <iostream>
usingnamespace
std;
int MARKS[] = {16, 2, 77, 40, 12071};
int n, result=0;
int main ()
{
for
( n=0 ; n<5 ; ++n )
{
result += foo[n];
}
cout << result;
return
0;
}
To learn more about
C++ at TCCI
,
Engineering class
,
EC Engineering class
,
civil engineering class
,
computer engineering class
Call us @ 98256 18292.
Visit us @ http://tccicomputercoaching.com/
No comments:
Post a Comment