top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

C: What is the difference between array and &array?

+2 votes
438 views

for example
int array[10];

If we print array and &array what will be the value and why?

posted Sep 25, 2014 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+1 vote

There is no difference because the name of an array will give you it address, and &array also does the same.

array;
&array;
&array[0];

all three are same they represent the base address of array.

printf("%p; %p; %p\n", array, &array, &array[0]);  //all will print the same memory address.
answer Sep 25, 2014 by Arshad Khan
0 votes

There will be no difference.
If you will print values of following:

array- it will print the base address of array.
&array- it will also print the base address of array.
&array[0]-it will print the address of first element of array which is base address only.

answer Sep 25, 2014 by Aarti Jain
Exactly. Just to summarize what Aarti said, "array name represents base address". So all these would refer to the same address.
...