1 2 3 4 5 6 7 8 9 10

constattached to a parameter means that the parameter will not change. In this case it means that the parameter StrOrig cannot be an L-value within the strcpy function.

Thus it can provide valuable protection and assurance that the copy will not be in the opposite direction!

So what is happening here?
Let us consider an example

char* s = "My sample string";
String tmp;
// char* tmp; strcpy (tmp, s);// tmp has a copy of s

First this is not the simple case in which tmp simply points to the original string s, as in:

tmp = s;

why on earth would we need strcpy to do this?

strcpy() actually does something like:

tmp = (String) malloc (1+strlen(s));

for ( i = 0; *(s+i) != '\0'; i++ )
*(tmp+i) = *(s+i);
return (tmp);

// space

4 February, 1998

6

Copyright University of Alberta