At the underlying machine code level the usual way to refer to an array is to give the memory address of the first element in the array. C works at a level not far removed from machine code. But whatever language you use, underlying it all, you are right: to change an array you do it one element at a time. Some languages help you more than others but at least in C it is possible to work out exactly what is going on.
There are attempts to make string handling in Wiring easier and more intuitive using C++ classes such as the (capital-S) String class. Now, I don’t think they make anything easier that way, but that’s me, others may disagree. You might want to give it a try. http://docs.spark.io/firmware/#other-functions-string-class
Q2: The parameters to a function are declared as local variables to the function. Each of your two functions compile down to the same code. Each declare the_label as a pointer to char.
char *p and
char p are equivalent.
strcpy(a, "somestring"); sets (=overwrites) the contents of array a [=sets the contents of a and subsequent memory locations] ending with the implied NUL char ‘\0’ at the end of “somestring”.
You can do the following:
s = "new value";
/* set the contents of character pointer s to the address of the beginning of this constant string
(the compiler puts the constant string in a special data area for you and sets label to point to it)
- nothing is changed, nothing is copied - a pointer is set */
s = "another string"; // s now points at another constant string
// and you can no longer reference the former string, although it is still there
// once again no string is changed or copied, only a pointer is set
strcpy( a, s);
/* copy the char at address s to address a, advancing one char at a time, until nul '\0' is encountered
This time data is copied, the addresses are not changed */
s = a; // set the contents of character pointer s to the address of the 1st element of a
a = 'x' ; //note single quotes for char double for string - the 5th element of char array a is set to 'x'
// note that in changing a we have also changed s - they're the same. And s is valid syntax!