I've found something strange about of arrays of pointers to characters.
constchar* a[]={"test1","test2"}
a[0] prints out "test1", and a[1] "test2".
What I don't understand: the array is supposed to contain addresses to places in the free store where actual characters are stored, not whole sequences of characters!
Can any one explain?
"test1" returns a pointer to a memory location with "test1" written in it.
When displaying a pointer to character, the contents of the memory location is displayed
a[0] is a pointer to a memory location where "test1" is stored. But the var on this location isn't really an ordinary character, but an array of characters:
so const char* a[]={"test1","test2"} is not just an array of pointers, but each element points to an array of characters?
If you use a print string function and pass it a pointer (a[0]) it will output all the characters in sequence until it reaches the null (\0) character.
is not a ordinary character, but an array of characters. That syntax is just so confusing! One should expect that the var a only stores "t" and then ignores everything else (as an int var would ignore all decimals as in "int i=2.9").
Lets try to break this down a bit; char* is a pointer to a char there is nothing special about it.
when you have some code such as: char* a = "test"; the characters test\0 are put into memory and the address of the first character is assigned to the pointer a. So now a points to the letter t.
Functions designed to iterate over the memory that will use the pointer as a starting place and then increment the memory address until they reach \0.