gpt4 book ai didi

C++ : Meaning of const char*const*

转载 作者:IT老高 更新时间:2023-10-28 23:14:48 30 4
gpt4 key购买 nike

在其中一个 C++ 程序中,我看到了一个函数原型(prototype):int Classifier::command(int argc, const char*const* argv)

const char*const* argv 是什么意思?和 const char* argv[] 一样吗?const char** argv 也一样吗?

最佳答案

来自 C++ Super-FAQ :

Read the pointer declarations right-to-left.

  • const X* p means "p points to an X that is const": the X object can't be changed via p.
  • X* const p means "p is a const pointer to an X that is non-const": you can't change the pointer p itself, but you can change the X object via p.
  • const X* const p means "p is a const pointer to an X that is const": you can't change the pointer p itself, nor can you change the X object via p.

And, oh yea, did I mention to read your pointer declarations right-to-left?

const char * const *char const * const * 相同: 一个(非 const)指针,指向一个指向 const char 的 const 指针。

const char *char const * 相同: 一个指向 const char 的(非 const)指针。

const char * *char const * * 相同: 一个(非常量)指向一个(非常量)指向一个常量字符的指针。

关于C++ : Meaning of const char*const*,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10029170/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com