-1

I am trying to achieve something in C and hope you guys can tell me where I went wrong.

So I have values that is an array of 6 const char pointers.

    int main() 
    {
      /* values is an array of 6 char pointers */
      const char *values[6] = 
       {
        "Two", 
        "Three", 
        "Four", 
        "Five", 
        "Six", 
        "Seven",
       };
       /* p is a pointer to a char pointer */     
       char *(*p) = &values[0];

    }

What I am doing here is to create p that is a pointer to a char pointer from my array and store the address of the first char pointer in my array into p.

Though the logic works, I keep getting a warning message saying:

warning: assignment from incompatible pointer type

What am I doing wrong?

user3702643
  • 1,465
  • 5
  • 21
  • 48

1 Answers1

2

You can't cast a const pointer to non-const.

const char *(*p) = &values[0];
^~~~~

This is what you should have written.

iBug
  • 35,554
  • 7
  • 89
  • 134