Reputation: 23
I define a typedef
typedef char* charP;
Then I declare a few variables
charP dog, cat, fish;
Are all the variables of type char*
or is dog
the only char*
while cat
and fish
are of type char
?
Upvotes: 2
Views: 197
Reputation: 148
All of them are char pointers as you are using typedef and not macro.
so it will not behave like char *dog, cat, fish;
Upvotes: 0
Reputation: 22280
All of them are char *
. Do not confuse it with this case: char *dog, cat, fish;
. Here, dog
is a char *
, and rest are just char
s.
Upvotes: 1
Reputation: 399813
All of them are of type charP
, which is an alias for char *
, so yes, they're all pointers.
That said, some people (me included) consider it a bad idea to "hide" the pointer asterisk, since it breaks the symmetry between declaring the variable and accessing it.
You're going to have:
charP a;
*a = '1'; /* What?! It didn't look like a pointer, above?! */
... which causes confusion. Generally, pointers in C are important to keep track of, so hiding what is a pointer and what isn't can lead to trouble.
Upvotes: 10