【发布时间】:2011-07-07 01:48:57
【问题描述】:
#include <stdlib.h>
#include <stdio.h>
struct foo{
int id;
char *bar;
char *baz[6];
};
int main(int argc, char **argv){
struct foo f;
f.id=1;
char *qux[6];
f.bar=argv[0];
f.baz=qux; // Marked line
return 1;
}
这只是一些测试代码,因此请忽略 qux 实际上并没有任何有用的东西。
我在标记行incompatible types when assigning to type ‘char *[6]’ from type ‘char **’ 上遇到错误,但两个变量在代码中都定义为char *[6]。有什么见解吗?
【问题讨论】:
-
char *baz[6];声明了一个包含 6 个指针的数组。如果你想声明一个指向数组的指针,写char (*baz)[6];