Reputation: 65
I came across to a question from one of my friend.
What is the difference between these?
* char ptr
char * ptr
Upvotes: 0
Views: 165
Reputation: 272467
The first declaration * char ptr
is not valid C syntax, so that is why you are getting a compile-time error. The second declaration char * ptr
is valid C syntax, because the type is listed first followed by the pointer '*' symbol and the variable name.
Upvotes: 3
Reputation: 48280
This is an error:
* char ptr;
This declares ptr
as a variable of type pointer-to-char:
char * ptr;
Upvotes: 4
Reputation: 612814
The first line, * char ptr;
, is not valid.
The second line, char * ptr;
declares a variable of type pointer to char.
Upvotes: 1