int numbers[20];
int * p;
Are the two assignments below the same?
p = numbers;
p = &numbers[0];
An array is a pointer, and you can store that pointer into any pointer variable of the correct type. For example, int A[10]; int* p = A; p[0] = 0; makes variable p point to the first member of array A.
To declare an array in C, we use the syntax: dataType arrName[arrSize]; Here, the dataType refers to the type of array, which can be an integer, float, a character, or a pointer.
How is the 2nd element in an array accessed based on pointer notation? a[2] is equivalent to *(a + 2) in pointer notation.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With