1

I want to know the difference between char pointer and pointer to char..? Are they same? If no what is the difference?

1
  • I'd say "same". If you're in C++ land, using a "const" qualifier, then there are subtle distinctions in your declaration for "pointer is const" vs. "what's pointed at is const". But as far as your question: the two terms are equivalent. IMHO.. Commented Jul 30, 2012 at 6:06

6 Answers 6

5

I think there is no difference between a "pointer to char" and a "char pointer".

char *p;

Both are just different ways to designate a pointer to char type.

Sign up to request clarification or add additional context in comments.

Comments

4

This question might make more sense if you backed it up with example code. As far as I'm concerned they mean the same thing, but I only ever think of "char pointer".

What I think you might mean is this:

char c = 'A';
char *pc = &c;            // <-- "pointer to char"?
char *p = new char [50];  // <-- "char pointer"?

In fact, pc and p above are both char pointers. They can both be used as arrays, although addressing anything other than the zeroth element of pc is going to cause problems.

Comments

2

char pointer and pointer to a char are same i.e. char *ptr;

but, if you mean pointer to char array then their is a difference.

pointer to char array is declared as char (*ptr)[n] which stores the address of an char array of size n.

Comments

2

There is no difference between the char pointer and pointer to char. Both are same. Normally text strings are represented in C by arrays of characters. Since arrays can be easily be manipulated by pointers it is often used.

Comments

2

The confusion arises when you replace char with double. People colloquially use double pointer to mean pointer to pointer to some type, not pointer to double type.

Comments

1

There is no difference. They are just written in a different way.

1 Comment

Why would they be written differently? Or you mean 'it's an alternative expression'?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.