Const char *char * constWhat is the difference between the above two?.

Showing Answers 1 - 6 of 6 Answers

Arun kumar varma

  • Jul 7th, 2005
 

In the first case, the pointer is constant and in the latter, the data pointed to by the pointer is constant.

  Was this answer useful?  Yes

ruchi

  • Jul 17th, 2005
 

 
This is the correct difference 
const char * implies pointer to a const char 
char * const means const pointer to a char 
 

  Was this answer useful?  Yes

Amit Sarkar

  • Apr 23rd, 2006
 

Correct Answer: No difference!!

  Was this answer useful?  Yes

vipull

  • Jul 25th, 2006
 

Const char *myPointer is a non constant pointer to constant data; while char *const myPointer is a constant pointer to non constant data.

  Was this answer useful?  Yes

In const char* p, the character pointed by ‘p’ is constant, so you cannot change the value of character pointed by p but you can make ‘p’ refer to some other location.

In char const* p, the ptr ‘p’ is constant not the character referenced by it, so you cant make ‘p’ to reference to any other location but you can change the value of the char pointed by ‘p

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions