我试图以char
不同的方式创建一个指针数组,但是只有第一种方法有效:
#include <stdio.h>
int main(){
char* a[] = {"hello"};
// works
char** b = {"hello"};
// warning: incompatible pointer types initializing
// 'char **' with an expression of type 'char [6]'
char c[][] = {"hello"};
// error: array has incomplete element type 'char []'
return 0;
}
我究竟做错了什么?
{"hello"}
语法识别为数组,这将导致代码中断。如果这样做,char** b = a
您会发现该语法确实有效。char c[][6] = {"hello"}
您可以观察到它的工作原理。本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句