Start New Discussion within our Software Development Community

i want to create array of pointer. "aa" "ab" "ac"

i tried many thing but it still give me error.

char *table[3] = "aa", "ab", "ac";


char *table[3];
*table[0] = "aa";
*table[1] = "ab";
*table[2] = "ac";

try something like this:

  char *array[3];
  char x = 'a', y = 'b', z = 'c';

  array[0] = &x;
  array[1] = &y;
  array[2] = &z;

  for (int i=0; i< 3; i++) 
      printf( "%d = %c\n", i, *(array[i]) );

got it to work with windows using cygwin and linux gcc...
is there a specific error or output that happens when you compile or run the code?

i want to create array of pointer. "aa" "ab" "ac"

You've forgotten brackets .. {}, i.e.

const char *table[3] = {"aa", "ab", "ac"};
This article has been dead for over six months. Start a new discussion instead.