Being pedestrian in reading function statement
This mistake happens due to the School of Style code of the person who wrote this function. I will write equivalent headers, each in a distinct style:
char *strcpy(char *dest, char *orig);
char* strcpy(char *dest, char *orig);
char *strcpy(char* dest, char* orig);
char * strcpy(char * dest, char * orig);
char* strcpy(char* dest, char* orig);
What is the difference between the above statements? For the compiler, none. There are for those who write and for those who read, but this is only at the level of code style.
Why there are these different style schools?
Well, each one has a proposal, a defended value. It’s kind of like asking "if you have Cubism, why did you use Dadaism?"...
If anyone writing with the pointer indicator always on the left side thought that the pointer indicator should be isolated from the words that surround it, the left style would have succumbed long ago.
I am from school who, in variable declaration, use the pointer indicator always pasted in the variable name. Why? Beauty counts? Furthermore, because the following two statements are identical:
int *p, i;
int* p, i;
In both cases, a pointer is being created p
and a whole i
. The idea of the school that I follow is to always show in the variable that it has this pointer indicator, avoiding that someone unintentionally interprets the i
be another pointer to integer.
Thus, it creates the habit of always separating the type from the *
, what may not be healthy. In functions, for example, I don’t see why reading disambiguation, only use because yes. Note that, as each argument comes preceded of its type, also becomes irrelevant the reason for reading improvement.
Summary
You wouldn’t say that char* strcpy(char* dest, char* orig);
begins with *
, would you say? So it doesn’t return a vector because it starts with *
, but returns a pointer because the type of return declared is character pointer char*
.
The asterisk is part of the return.
strcpy
is a function that returnschar*
: char pointer (the fact that the asterisk is near the function name or the type name makes no difference).– marcus