Consider the two following lines of code:
const char *ptr = "Hello";
char arr[] = "Hello";
"Hello"
ptr
"Hello"
arr
const char * const ptr = "Hello";
const char arr[] = "Hello";
const char
ptr
Here's a few differences.
First off, this may hold true on certain implementations as the pointers can point to the same memory:
const char * const ptr1 = "Hello";
const char * const ptr2 = "Hello";
ptr1 == ptr2;
But it cannot be true using the array form.
Anyway, the real difference is that their types are different. In particular, the char[]
version retains its size in the array type. So sizeof(arr)
gives you the size of the array, rather than a pointer, and you can also create pointers to arrays to arr
.