Array Representation:
Shown below some example of array defination for assignment of initial values:
int digit[10] ={1,2,3,4,5,6,7,8,9,10};
float f[10]={0.3,0,0.25}
For example, i want to represent five integer number in an array,say(10,20,30,40,50) by an array variable name number,then declaration of array variable number as followes:
int number[5] ;
The values to the array elements can be assigned as follows:
number[0]=10;
number[1]=20;
number[2]=30;
number[3]=40;
number[4]=50;
For this case the array number stored valued as shown below:
number[0] | 10 |
number [1] | 20 |
number [2] | 30 |
number [3] | 40 |
number [4] | 50 |
Also consider the following array definition:
int number[5]={1,5,8};
The values to the array elements can be assigned as follows:
number[0]=1;
number[1]=5;
number[2]=8;
number[3]=0;
number[4]=0;
Note:character type array use last index for null('\0') .
char name[6]={"hasan"};
the array elements are stored as follows:
Note:character type array use last index for null('\0') .
char name[6]={"hasan"};
the array elements are stored as follows:
name[0]='h';
name[1]='a';
name[2]='s';
name[3]='a';
name[4]=n'';
name[5]='\0';
No comments:
Post a Comment