无法从"char *[]"转换为 "const char **"
#include <stdio.h>
void display_car_brands(char *brand_table[], int size)
{
char const **cbp;
for(cbp = brand_table; cbp < brand_table+ size; cbp++)
{
printf("%s\n", *cbp);
printf("%c\n",**cbp);
}
}
int main( )
{
char *cars[] = { "ASTONMARTIN",
"AUDI",
"BENZ",
"BENTLEY",
"BMW",
"BUGATTI",
"FERRARI",
"JAGUAR",
"LAMBORGHINI",
"MASERATI",
"MAYBACH",
"ROLLS ROYCE"
};
int array_size = sizeof(cars) /sizeof(cars[0]);
display_car_brands(cars,array_size);
return 0;
}
程序报错:error C2440:"=":无法从"char *[]"转换为 "const char **"
[解决办法]
char const **cbp;
去掉const修饰符
[解决办法]
#include <stdio.h>
void display_car_brands(const char *brand_table[], int size)
{
const char **cbp;
for(cbp = brand_table; cbp < brand_table+ size; cbp++)
{
printf("%s\n", *cbp);
printf("%c\n",**cbp);
}
}
int main()
{
const char *cars[] = { "ASTONMARTIN",
"AUDI",
"BENZ",
"BENTLEY",
"BMW",
"BUGATTI",
"FERRARI",
"JAGUAR",
"LAMBORGHINI",
"MASERATI",
"MAYBACH",
"ROLLS ROYCE"
};
int array_size = sizeof(cars) /sizeof(cars[0]);
display_car_brands(cars,array_size);
return 0;
return 0;
}
//注意const的用法