What is the difference between static const and const?

后端 未结 4 581
借酒劲吻你
借酒劲吻你 2020-11-30 20:21

What is the difference between static const and const? For example:

static const int a=5;
const int i=5;

Is there

4条回答
  •  暖寄归人
    2020-11-30 20:48

    static determines visibility outside of a function or a variables lifespan inside. So it has nothing to do with const per se.

    const means that you're not changing the value after it has been initialised.

    static inside a function means the variable will exist before and after the function has ended.

    static outside of a function means that the scope of the symbol marked static is limited to that .c file and cannot be seen outside of it.

    Technically (if you want to look this up), static is a storage specifier and const is a type qualifier.

提交回复
热议问题