dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 18 of 18

Thread: [RESOLVED] C++ constant pointer

  1. #16
    Join Date
    May 2018
    Posts
    67

    Re: C++ constant pointer

    Quote Originally Posted by 2kaud View Post
    Code:
    char a1[] = "test";
    const char a2[] = "test";
    char const a3[] = "test";
    a1 is a constant pointer, you can change every value of array that is 'test'
    a2 and a3 are the same: you cannot change array values, that is "test" data.

    where the definition of a2 and a3 means the same.
    It was answer I'm searching!

    for a pointer you have:

    Code:
    char * p1;
    char * const p2;
    char const * p3;
    const char * p4;
    char const * const p5;
    const char * const p6;
    Now see if you can explain the differences between a1, a2, a3, p1, p2, p3, p4, p5, p6
    p1: no costant pointer, you can change both its memory address and data pointed.
    p2: constant pointer, you cannot change value of pointer but only pointed data.
    p3: no constant pointer, you cannot change pointed data.
    p4: as p3.
    p5: constant pointer and you cannot change data pointed
    p6: as p5


    it's ok?

  2. #17
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,464

    Re: C++ constant pointer

    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2017 (15.8.7)

  3. #18
    Join Date
    May 2018
    Posts
    67

    Re: C++ constant pointer

    Quote Originally Posted by 2kaud View Post
    Thanks again for your patience!

Page 2 of 2 FirstFirst 12

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




On-Demand Webinars (sponsored)