C++ Memory Management: What is the difference between 'const char*' and 'char*const'?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1

Thread: C++ Memory Management: What is the difference between 'const char*' and 'char*const'?

Hybrid View

  1. #1
    Join Date
    Aug 2002
    Location
    Madrid
    Posts
    4,588

    C++ Memory Management: What is the difference between 'const char*' and 'char*const'

    Q: What is the difference between 'const char*' and 'char*const'?

    A:

    Code:
    char* const
    declares a constant pointer which has both read and write access to a character (or character array). The pointer itself is a constant and you can not change it. Like all other constant variables, you must initialize it with a constant value at the same time when it is declared:

    Code:
    char buffer[80];
    char* const pBuffer = buffer;
    Code:
    const char*
    declares a pointer to a constant character (or a constant character array). The pointer can be changed, but the character (or array) to which it points can not be changed.


    FAQ contributed by: [Kevin Hall]


    Last edited by Andreas Masur; July 23rd, 2005 at 02:50 PM.

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center