My brain has gone a lot fuzzy just recently and I can't for the life of me remember why the following C code:
char a[3][3] = { "123", "456", "789" };
char **b = a;
Generates the following warning:
warning: initialization from incompatible pointer type
Could someone please explain this for me.
Thank you.
char (*b)[3] = a;
This declares b
as a pointer to char arrays of size 3. Note that this is not the same as char *b[3]
, which declares b
as an array of 3 char pointers.
Also note that char *b = a
is wrong and still emits the same warning as char **b = a
.
Try this,
char a[3][3] = { {'1','2','3'}, {'4','5','6'}, {'7','8','9' }};
char *b = &a[0][0];
Since, a is character array of arrays you need to initialize them as a character.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With