File tree Expand file tree Collapse file tree 1 file changed +17
-4
lines changed Expand file tree Collapse file tree 1 file changed +17
-4
lines changed Original file line number Diff line number Diff line change 1+ //The & operator is used to get the address.
2+ //But in case of array the name of array itself returns its address.
3+ //In array the elements occupy consecutive address,
4+ //therefore incrementing it by 1 each time would give
5+ //the address of next element.
6+
17#include<stdio.h>
28int main()
39{
410 int a[100],i,n,*add;
5- printf("enter the size");
11+
12+ printf("enter the size: ");
613 scanf("%d",&n);
7- printf("enter the no");
14+
15+ printf("enter the numbers: \n");
816 for(i=0;i<n;i++)
917 {
1018 scanf("%d",&a[i]);
1119 }
20+
1221 for(i=0;i<n;i++)
1322 {
14- add=(a+(i*sizeof(int)));
15- printf("%u\n",add);
23+ add=a+i;
24+ //add = &a[i]; would also return the same thing.
25+ printf("The address of element %d is %u.\n",*add, add);
26+
27+ //Notice: As size of int is 4-byte the differnce in address
28+ //of cosecutive elements is 4.
1629 }
1730}
You can’t perform that action at this time.
0 commit comments