Results 1 to 5 of 5

Thread: Question in C++??

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 1999
    Posts
    50

    Unhappy

    Hi everybody,

    My question is: What is the difference between these two statements const char* p and char* const p ?

    I appreciate your help,

    Wesam

  2. #2
    Lively Member
    Join Date
    Sep 2000
    Location
    Singapore
    Posts
    78
    const char* p
    is a pointer to a constant char. The value that is pointed to can't be change.

    char* const p
    is a constant pointer to a char. The char can be change but it can't point to anything else.

    Hope this helps...

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 1999
    Posts
    50

    Smile

    Thank you, it helped; but may I ask another question in the same context: what is the advantage of declaring a pointer to a constant char for example where we can't change the value of that char and where we can set the pointer to point to different thing??

    Wesam,

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    If you have a char* variable as a member of your class. You supply a const pointer, so that they can change the pointer, but are not allowed to change the string inside your class.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  5. #5

    Thread Starter
    Member
    Join Date
    Feb 1999
    Posts
    50

    Cool

    Thank you,

    Wesam

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width