top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is the difference between const char *myPointer and char *const myPointer?

+1 vote
658 views
What is the difference between const char *myPointer and char *const myPointer?
posted Jan 6, 2015 by Emran

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

4 Answers

+3 votes

First one mean "pointer to a constant" and second one is "constant pointer". In first case "content can't modify" while in second case myPointer can not point to another location.

answer Jan 6, 2015 by Vikram Singh
+2 votes

Below Example Will Help You In Understanding The Difference:

1)const char *myptr
Ex:
char ch = 'a';
const char *myptr = &ch;
*myptr = 'b' <---- Not Possible
myptr++; <-----Possible

2)char *const myptr
Ex:
char ch = 'a';
const char *myptr = &ch;
*myptr = 'b' <---- Possible
myptr++; <-----Not Possible

answer Jan 7, 2015 by Chirag Gangdev
+1 vote

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

answer Jan 8, 2015 by Mohammed Hussain
+1 vote

const char *myPointer is a pointer to a const char, and char *const myPointer is a constant pointer to a char.

answer Jan 15, 2015 by Chirag Jain
Similar Questions
+2 votes

A char can not be a +ve or -ve. last bit is signed bit in accumulator.but not useful for CHAR Whats the purpose? of doing it.

+4 votes

What's the purpose of const pointers?

0 votes

Trivial question, please help.

I need to convert a string literal like "111.25" to floating point number.
atof() fails me as it returns 1111 and discards .25?

...