How do I create a pointer that points to an array who's pointed addresses cannot be modified?
<p>I'm currently trying to learn C++. In learning, I like to try weird things to get a grasp of the language and how memory works. Right now, I'm trying to create a class who has an array of characters that is set on construction. The only method of my class is to be able to get the array via a pointer on an argument. I've successfully created my class and it works just fine, but now I want to make it more secure by making sure that I never change the value of the array.</p>

<p>This is what I have so far:</p>

<pre><code>#import &lt;stdio.h&gt;

class MyClass {
    public:
        char const * myArray;
        MyClass(char inputChar[]){
            myArray = inputChar;
        }

        void get(const char * retVal[]){
            *retVal = myArray;
        }
};

int main(){
    char myString[] = {'H','E','L','L','O'};
    MyClass somethingNew = MyClass(myString);
    const char * other = new char[4];
    somethingNew.get(&amp;other);
    std::cout &lt;&lt; other[0];
    return 0;
}
</code></pre>

<p>I noticed that I cannot change the value of the array at all by using the dereference operator:</p>

<pre><code>myArray[0] = 'h';
</code></pre>

<p>And this is good, but that doesn't mean that I cannot change the pointer of where myArray[0] points to:</p>

<pre><code>*(&amp;myArray) = new char('h');
</code></pre>

<p>Is there any way to prevent against this?</p>

<p>--- Resolution ---</p>

<pre><code>#import &lt;stdio.h&gt;

typedef const char * const constptr;

class MyClass {
    public:
        constptr * myArray;
        MyClass(constptr inputChar) {
            myArray = &amp;inputChar;
        }

        void get(constptr * retVal){
            retVal = myArray;
        }
};

int main(){
    char myString[] = "Hello";
    MyClass somethingNew(myString);
    constptr other = new char[4];
    somethingNew.get(&amp;other);
    std::cout &lt;&lt; other[0];
    return 0;
}
</code></pre>

<p>This means that I cannot do any of the following:</p>

<pre><code>*myArray[0] = 'h';
*myArray = new char[4];
*&amp;*myArray = new char('h');
</code></pre>

<p>But I can do this:</p>

<pre><code>myArray = &amp;inputChar;
</code></pre>
