Arrays:
- Array is a collection of similar data items that are stored under a single name.
- value in an array is identified by index enclosed in square brackets with array name.
syntax: datatype array-name[size];
int a[3];
this can represents array of integer.
- In array the elements are stored in continuous memory location.
- The starting memory location is represented by the array name called base address of the array.
Initialization of array :
- After the declaration of an array its elements must be initialized otherwise they contain garbage values.
syntax:
data-type array-name[size]={list of values};
int a[5]={25,26,27,28,29};
data-type array-name[size]={list of values};
int a[5]={25,26,27,28,29};
- int a[]={25,26,27,28,29};
- int a[5]={1,2,3};
Accessing of Array:
- After initialization array elements can be access by subscripts.
example: int a[]={25,26,27,28,29};
This can be shown as follows:
- Here 0,1,2,3,4 are subscripts and has address of values.
- In array the elemenys are stored in continuous memory location.
- Address of the first location in array is called base address.
- Elements can be accessed by c[0] is 25,c[1] is 26,c[2] is 27,c[3] is 28, c[4] is 29.
program on accessing the numbers from array:
You can also refer
----------------------------------------------------------------------------------------------------------
No comments:
Post a Comment