Question about weird pointer
I study C. Digging in some C source code where I f开发者_运维百科ound that line. I have read about pointers, but I did not see such an example.
char *uppercase (char *s);
What that mean ?
It's a declaration of a function that takes a char pointer and returns a char pointer.
That means that the function takes a pointer to a character and returns a pointer to a character i.e the start of the string.
char *uppercase (char *s);
is the same as
char* uppercase (char *s);
Its return type is char*; it returns a pointer.
uppercase is afunction which returns a char type address ( that is, it can be stored in a char pointer ) as its written as char *uppercase...
uppercase() takes a char pointer as argument char *s...
therefore its written as char *uppercase( char *s).
In C the location of the * doesn't matter as long as it is somewhere between the type and name. So char* s is the same as char *s and even char * s.
The same applies to functions and their return types, char* uppercase() is equivalent to char *uppercase() and char * uppercase().
White-space is more or less ignored in C so when writing your own code I recommend you pick one format and stick with it.
The location of the asterisk * can be anywhere: between return type or function name.
It is more logical to keep it on the return type's end i.e. char*
加载中,请稍侯......
精彩评论