Clarification of “The meaning of a value is determined by the type of the expression used to access it”

  Kiến thức lập trình

From §6.2.5(1) of the standard:

The meaning of a value stored in an object or returned by a function is determined by the type of the expression used to access it. (An identifier declared to be an object is the simplest such expression; the type is specified in the declaration of the identifier.)

I am confused by the second sentence, specifically this bit: “An identifier declared to be an object is the simplest such expression” – how is this an example of what the first sentence is saying? What object is being accessed when we declare an identifier to be an object? Also, isn’t this a declaration rather than an expression?

When I read the first sentence, I thought it was referring to a scenario such as the following:

int x = 3.2;        // `float` object is interpreted as an `int`

Here, the float object 3.2 is accessed by an assignment expression of type int and therefore the float object is interpreted as an int. Is this what the first sentence in the quote is saying?

New contributor

user135792 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

LEAVE A COMMENT