【发布时间】:2020-08-29 08:01:55
【问题描述】:
谁能解释一下下面两段代码的区别:
func1 (...)
{
int32_t index;
const int32_t *p;
p =& (index);
}
func2 (...)
{
const int32_t s;
s=10;
}
可以声明一个 const 指针,然后给它赋值,但不能声明一个普通变量,然后给它赋值。谁能给我解释一下?
我收到一个 pc-lint 错误,我必须在函数内声明 const 变量,但我做不到。我怎样才能摆脱这个错误?
非常感谢。
【问题讨论】:
-
您可以在声明中添加“number_of_stars + 1”
const;const适用于其直接右侧的任何内容:int [const] * [const] * ... [const] foo = value; -
const int32_t s; s = 10;编译器错误 ...int32_t * const p; p = NULL;编译器错误
标签: c variables memory constants pc-lint