jingo
jingo

Reputation: 1074

Question about weird pointer

I study C. Digging in some C source code where I found that line. I have read about pointers, but I did not see such an example.

char   *uppercase (char *s);

What that mean ?

Upvotes: 2

Views: 152

Answers (6)

Sorter
Sorter

Reputation: 10220

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*

Upvotes: 0

nobsid
nobsid

Reputation: 186

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.

Upvotes: 0

Haywire
Haywire

Reputation: 878

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).

Upvotes: 0

rickythefox
rickythefox

Reputation: 6851

It's a declaration of a function that takes a char pointer and returns a char pointer.

Upvotes: 6

orlp
orlp

Reputation: 117691

char   *uppercase (char *s);

is the same as

char* uppercase (char *s);

Its return type is char*; it returns a pointer.

Upvotes: 0

Deleted
Deleted

Reputation: 4998

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.

Upvotes: 0

Related Questions