What does 'designate an object' mean in C?

前端 未结 1 697
渐次进展
渐次进展 2021-01-26 19:22

For example,

int x = 10;

we say that \"x designates an int object which stores 10\". But what does \"designate\" exactly mean? Doe

1条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-26 19:45

    1. x is an identifier.
    2. There is an int object (i.e. a region of storage) containing the value 10.
    3. The identifier x is associated with that int object.

    The C standard uses the English word designate to express the relationship between an identifier and the object it identifies. You could say the same thing in several different ways. I said "associate" just now, there are many words we could choose. "x is a label for this region of memory" would be another way.

    Note: designating is not limited to identifiers. Other expressions can designate an object too. For example *(&x) also designates the same object, as does *(&x + 0).

    When an expression designates an object, the expression may be used to either assign a value to the object, or retrieve the value from the object. (The same syntax covers both of those cases; it depends on context whether the value is read or written).

    The word lvalue means an expression that might designate an object (according to the above definition of 'designate').

    0 讨论(0)
提交回复
热议问题