Reputation: 16122
int numbers[20];
int * p;
Are the two assignments below the same?
p = numbers;
p = &numbers[0];
Upvotes: 20
Views: 7315
Reputation: 381
numbers[0] is equal to *number and equal to *(number+0)
numbers[x] = *(number+x)
so &(*(number+x) ) = number+x which is the address of x'th element
Upvotes: 2
Reputation: 206528
Yes both are same.
In this case, Name of the array decays to a pointer to its first element.
Hence,
p = numbers; //Name of the array
is same as:
p = &numbers[0]; //Address of the First Element of the Array
Upvotes: 25
Reputation: 146910
Yes, they are the same. When an array's name is invoked in an rvalue context, it decays to a pointer to its first element.
Upvotes: 16