Ria_546
Ria_546

Reputation: 65

what does this pointer syntax in C mean?

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

Answers (3)

Oliver Charlesworth
Oliver Charlesworth

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

Adam Liss
Adam Liss

Reputation: 48280

This is an error:

* char ptr;

This declares ptr as a variable of type pointer-to-char:

char * ptr;

Upvotes: 4

David Heffernan
David Heffernan

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

Related Questions