There is an incompatible types error because you are assigning arrays of strings (type char * in C) to arrays of pointers to ints (such as int *x[]
). The error message given by the compiler is a little confusing because C does a lot behind the scenes to try to convert variables from one type to another.
As chars are represented internally as numbers (letters correspond to their ASCII values), C is able to convert characters to ints, so it attempts to treat variables x and y as arrays of pointers to chars instead of ints, hence the char *[3]
. It sees {"foo", "bar", "baz"} as type char **
because strings are type char *
and arrays essentially stored as pointers in C, so it is a pointer to char *
, or char **
.
While this doesn't completely relate to your question, I also wonder what you're trying to do with x = y;
As it is written, that will make x point to the same array as y, leaving the array that x used to point to inaccessible. To check whether two variables in C are equal, you would use the == operator. Testing equality isn't as simple for arrays or strings, but that's completely outside the scope of this question.