简体   繁体   中英

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. It points to pointers to const chars. You can however:

 const char **foo() {
   const char **bar;
   ...
   return bar;
  }

bar被声明为const char **但是您将返回char **

这是因为函数foo返回char ** ,而barconst char **类型。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM