In C, are const variables guaranteed to be distinct in memory?

前端 未结 4 2171
死守一世寂寞
死守一世寂寞 2021-02-08 02:47

Speaking of string literals, the C99 standard says (6.4.5.6):

It is unspecified whether these arrays are distinct provided their elements have the appropr

4条回答
  •  醉话见心
    2021-02-08 02:54

    In

    const int x=12;
    const int y=12;
    

    x and y are different variables (both const-qualified) and therefore have different addresses.

    The same for the other example.

    Note that const is a qualifier for an object. Regarding memory layout, it makes no difference if it's there or not.

提交回复
热议问题