C Interview Questions and Answers

 

Is a pointer a kind of array?

I'm still mystified. Is a pointer a kind of array, or is an array a kind of
pointer?





An array is not a pointer, nor vice versa. An array reference (that is, any mention
of an array in a value context), turns into a pointer



There are perhaps three ways to think about the situation:



1. Pointers can simulate arrays



2. There's hardly such a thing as an array (it is, after all, a ``second-class
citizen''); the subscripting operator [] is in fact a pointer operator.



3. At a higher level of abstraction, a pointer to a block of memory is effectively
the same as an array (though this says nothing about other uses of pointers).





But, to reiterate, here are two ways not to think about it:



4. ``They're completely the same.''



5. ``Arrays are constant pointers.'

Posted by:Richards