A string is a sequence of characters. There is an order. In English it is left to right. They are really defined by a set of operations:
In C++, strings, or cstrings are represented as an array of characters. To mark the end of the string, we store the NUL character in the array element after the last character. Remember, the array holds the string, it is not the string. The string can be shorter than the array.
For example, the string "hello" is stored in a character array like this:char str[6];
h | e | l | l | o | \0 (NUL) |
If we were to make a pointer
to this array, it would be a character pointer because the type of the
things in the array is character.
In general, if you have an array of some
type, a pointer to this array is of the type a pointer to the type.
For example. if we have an array on integers like this,
int example_array[10];
To make a pointer to this array we do
int *ptr;
Think of it as if we make a pointer to the first thing in the array.
Here are some bits of code to manipulate strings
// find the length of a string int strlen(char * ptr) { int n=0; while(ptr[n] != '\0') n++; return n; } // strlenor
// find the length of a string int strlen(char ptr[]) { int n=0; while(ptr[n]) n++; return n; } // strlen