何时使用const*与const*const?

use*_*000 2 c

我见过代码,人们将使用const作为函数的参数.使用const*vs const*const有什么好处?这可能是一个非常基本的问题,但如果有人能够解释,我将不胜感激.

Bool IsThisNumberEqualToFive(int const * num)
{
    return(Bool)(5 != num );
}

Bool IsThisNumberEqualToFive(int const * const num)
{
    return(Bool)(5 != num );
}
Run Code Online (Sandbox Code Playgroud)

cni*_*tar 6

  • 在第一个版本,你答应你不会写入到该对象num指向
  • 在第二个版本中,你承诺并且你也会阻止自己(即IsThisNumber ..)将其num指向别的东西.

也就是说,在第二个版本中,指针本身也是const指针对象.