[英]returning pointer to a pointer in c
I'm trying to return a pointer to a pointer from a function. 我正在尝试从函数返回一个指针。
I have the following function 我有以下功能
char **foo() {
const char **bar;
...
return bar;
}
and I get the following warning: 我收到以下警告:
warning: return from incompatible pointer type [enabled by default]
what am I missing? 我想念什么?
You can't jsut cast away the const qualifier like that. 您不能像这样丢弃const限定符。 It points to pointers to const chars.
它指向const char的指针。 You can however:
但是,您可以:
const char **foo() {
const char **bar;
...
return bar;
}
bar
被声明为const char **
但是您将返回char **
这是因为函数foo
返回char **
,而bar
是const char **
类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.