Here is the code:
#include <stdio.h>
void test(const char* anagrams[])
{
while(*anagrams != NULL) {
printf("%s\n", *anagrams);
anagrams++;
}
}
int main()
{
char *arr[] = {"cat", "bat", "mate", "tac", "tab", "act", "tame", NULL};
printf("%lu\n", sizeof(arr));
test(arr);
}
This code generates the following warning:
$ gcc const_char_star_star.c
const_char_star_star.c:16:8: warning: passing 'char *[8]' to parameter of type 'const char **' discards qualifiers in nested pointer types [-Wincompatible-pointer-types-discards-qualifiers]
test(arr);
^~~
const_char_star_star.c:3:23: note: passing argument to parameter 'anagrams' here
void test(const char* anagrams[])
^
1 warning generated.
If I remove the const qualifier in the arguments for test, it compiles without any warning.