C language A is not an lvalue, how to interpret it

Updated on technology 2024-05-17
8 answers
  1. Anonymous users2024-02-10

    The assignment expression returns the result, for example, the return value of x=2*y is the same as the value assigned to x.

  2. Anonymous users2024-02-09

    This self-addition and self-subtraction is actually very simple, consisting of a variable i and a self-addition symbol ++.

    In the first case, the variable is in front, such as i++, the value of i is used first, and then 1 is added to the second case: the ++ sign is in front, for example: ++1, the value of i is added by 1 first, and then used.

    If it is i++ first, then use the value of i to show 5, then i adds 1 to become 6 and then j --, the value of j used, shows 5, and then subtracts 1 to 4 again.

    i: i adds 1 to 7 and then shows 7

    j : j -1 becomes 3 before 3 is displayed

    And there is a third one:

    i++ is the same as the first one, use it first and then add 1, so it shows 7, then adds 1, and becomes 8, but it is not displayed.

    j-- is also used first and then subtracted, so 3 is displayed, and then 1 is subtracted to become 2, but it is not displayed.

    As for the last two, think about it yourself, the same reason.

    In fact, just look at the first symbol, the first one is a variable, use it first and then calculate, the first one is ++ or --, it will be calculated and then used.

  3. Anonymous users2024-02-08

    lvalue and rvalue precede compilation. In C, two values on either side of the assignment operator are declared, the left is called lvalue, and the right is called rvalue.

    Definition: An lvalue is an expression that can be used as an lvalue if it can be referenced to an object, and the object is a piece of memory space that can be inspected and stored.

    An rvalue refers to a reference to a piece of data stored in a memory address.

    As can be seen from the above two definitions, lvalues actually refer to an object, and an object must have a name in our program or can be accessed by a name, so lvalues can be summarized as: lvalues mean that there must be a specific name in the program that references to this value. The rvalue refers to the content in the address, so the rvalue can be summarized as:

    An rvalue means that there is no specific name in the program that references this value.

    A, because the return result is the same as the A after the operation, ++A returns the real A, which can be re-assigned, so it can be used as an lvalue. A++ returns a before the operation, and at this time a has +1, the returned data is actually a in the past, it is copied from another place, not the real a, so it cannot be assigned, so it can only be an rvalue.

    So a++; The order of execution is to copy the value of a first, perform the overall calculation, and then a=a+1.

  4. Anonymous users2024-02-07

    The discussion was lively, but I don't think it's that complicated. ++a can be an lvalue because ++a is "a variable" - i.e., variable a after a=a+1. is a variable that acts as an lvalue of the expression.

    A++ is not a variable, it is an expression - i.e. a+1, it has not yet calculated the value of a+1 and assigned it to a, so it cannot act as an lvalue - who has seen int a, b; And then a+1=9 or a+b=1000 or b+4=a+cos(b)? The meaning is not clear, so C is not allowed, and the expression cannot be assigned a value ......

  5. Anonymous users2024-02-06

    A++ is a separate operation, that is, you can't perform the first half of the operation first, then perform other operations, and then execute the second half of the operation, so if A++ returns A, and A increments by 1, the returned A must be the self-incrementing ......

  6. Anonymous users2024-02-05

    Isn't the execution order of a++ returned a first, and then a=a+1 This is correct, but the value of the expression a++ is the value before a, not the value after a+1, that is, the result of the expression a++ is no longer synchronized with a.

    Since it is not synchronized with A, then it is not object A, and its address cannot be obtained, it is just a value, not an object, so it is an rvalue.

  7. Anonymous users2024-02-04

    The order of operation of a++ is from right to left. That is, the value of a+1 is calculated first and assigned to a.

  8. Anonymous users2024-02-03

    The so-called rvalue is a value that can only be placed to the right of the equal sign, that is, it can only be assigned to other variables, but cannot be assigned.

    A, because the return result is the same as the A after the operation, ++A returns the real A, which can be reassigned.

    A++ returns a before the operation, and at this time a is already +1, and the returned data is actually a from the past, which is copied from another place, not the real a, so it cannot be assigned.

Related questions
8 answers2024-05-17

find is used to find other text strings.

within text) and returns the starting position number of find text, starting with the first character of within text. You can also use search to find a text string in other text strings, but, unlike search, find is case-sensitive and doesn't allow wildcards. >>>More

8 answers2024-05-17

If the main function does not end with a return statement, C specifies that the compiler will automatically add a return to the generated object file to indicate that the program exits normally. However, I would suggest that you add a return statement to the end of the main function, about void main In C and C++, the prototype of the function that does not receive any arguments and does not return any information is "void foo(void); Probably because of this, many people mistakenly think that if the program doesn't need to return any information, they can define the main function as void main(void). However, this is wrong! >>>More

13 answers2024-05-17

Unless you overload the domodal function, the return value can only be the standard two. >>>More

12 answers2024-05-17

When the interpreter is wrong.

If there is a relevant character in the instr, it returns the location, and if it does not exist, it returns 0 >>>More

10 answers2024-05-17

When the computer performs the calculation, it first allocates the address space according to the type of data, and after allocating the address, it first converts the input data into binary, and then performs the calculation. The value you enter a, which is logically correct, but is a pathological function from the point of view of the calculation algorithm, is a value that is prone to errors when the computer converts binary. As you can see from this, computers are not as smart as you.