我使用的是 Visual Studio 2013。 今天,我对指针做了一些研究,当尝试指向另一个指针时,我发现错误。 这一行发生了错误: 字符 *cPP = &cP; 当尝试读取cP的地址并放入cPP时。 Visual Studio 宣布:
a value of type "char **" cannot be used to initialize an entity of type "char *"
你能解释一下吗?
我该如何修复这个错误?
#define stop __asm nop
int main()
{
char a = 'A';
char *cP = &a;
char *cPP = &cP;
stop
return 0;
}
最佳答案
#define stop __asm nop
int main()
{
char a = 'A';
char *cP = &a;
char **cPP = &cP;
stop
return 0;
}
必须有 2 ** 来定义指向指针的指针 (* to *)
关于c++ - 使用指针到指针时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46757165/