Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7641745

Browse files
Merge pull request #185 from tyadav4268/patch-1
Update Address of 1-D array
2 parents d69d3bf + 0d07504 commit 7641745

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

‎Address of 1-D array‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
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>
28
int 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
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /