char a[] = "hello";
My understanding is that a
acts like a constant pointer to a string. I know writing a++
won't work, but why?
No, it's not OK to increment an array. Although arrays are freely convertible to pointers, they are not pointers. Therefore, writing a++
will trigger an error.
However, writing
char *p = a;
p++;
is fine, becuase p
is a pointer, with value equal to the location of a
's initial 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