- Array elements are randomly accessed.
- Array Can be accessed using Array-Name and Subscript Variable written inside pair of Square Brackets [].
- Example -
arr[3] = Third Element of Array arr[5] = Fifth Element of Array arr[8] = Eighth Element of Array
How Elements gets Assigned ?
Real Thing ? How a[4] Works ????arr[0] = 51 arr[1] = 32 arr[2] = 43 arr[3] = 24 arr[4] = 5 arr[5] = 26
We know that array is declared like this -
int arr[] = { 51,32,43,24,5,26};
- So already we have base address of Array
- Consider *arr will gives Zeroth Element from Array.
- Similarly *(arr+0) will also yields same result.
Generally Accessing a[i] means retrieving element from address (arr + i) .Observations and Conclusion :
all of the above notations yields same result.arr[i] = 5 *(arr+i) = 5 *(i+arr) = 5 i[arr] = 5
Let's Prove it -
Output :#include< stdio.h> #include< conio.h> void main() { int arr[] = { 51,32,43,24,5,26}; int i; for(i=0;i<=5;i++) printf("\n%d %d %d %d",arr[i],*(i+arr),*(arr+i),i[arr]); getch(); }
51 51 51 51 32 32 32 32 43 43 43 43 24 24 24 24 5 5 5 5 26 26 26 26
0 Comments:
Post a Comment
Your Feedback :This is Growing Site and Your Feedback is important for Us to improve the Site performance & Quality of Content.Feel Free to contact and Please Provide Name & Contact Email