0

Assume this:

int a = 5;
int *p = &a;

int c = *p;
int d = p[0];

So is *p equivalent to p[0] in the world of the pointers and arrays?

chux - Reinstate Monica
  • 143,097
  • 13
  • 135
  • 256
  • 1
    Better duplicate: https://stackoverflow.com/questions/381542/with-arrays-why-is-it-the-case-that-a5-5a – Govind Parmar Mar 10 '20 at 14:57
  • If by "equivalent," you mean "they return the same thing," yes, they do. Obviously your choice of which to use will depend on what your stated intent is in your code. – Robert Harvey Mar 10 '20 at 15:31
  • 1
    This might be more helpful: [Do pointers support “array style indexing”?](https://stackoverflow.com/questions/55747822/do-pointers-support-array-style-indexing). – Lundin Mar 10 '20 at 15:52

0 Answers0