May I ask about the autoincrement operator in C

Updated on technology 2024-02-09
7 answers
  1. Anonymous users2024-02-05

    + Follow the right binding rule;

    a=++i++;Equivalent to int temp=i++, a=++temp;

    But temp is equivalent to a constant, and ++ cannot be applied to a constant, so this statement is wrong;

    a=i+++i;Equivalent.

    int temp=++i,a=i+++temp;But there are three + in the middle, and there is an objection to the combination, so this statement cannot be compiled.

    a=++i+++i;Three + objections cannot be compiled;

    int a,i=1;

    a=i-++i;equivalent to int temp=++i,a=i-temp;

    After execution, temp=2, i=2, a=0;

  2. Anonymous users2024-02-04

    For the implementation principle inside the compiler, refer to "Compilation Principles". This is the problem of lexical analysis and grammatical analysis

  3. Anonymous users2024-02-03

    It can only be used for variables and cannot be used for constants, which is a syntax provision, constants are used as read-only variables, and direct modification of constants will cause an error in the compilation stage, and variables modified by const are also read-only variables, and modification is prohibited. Here's how:

    1. First, define a variable i and assign an initial value of 6.

    2. Next, realize the self-addition of variable i, note that the ++ sign is after the variable.

    3. Finally, the self-incrementing value of the output variable i is shown in the figure below.

    4. Run the program, and you can see that the result is 7, indicating that the self-increment has been successfully realized.

    5. Move the auto-increment sign ++ in the program to before variable i.

    6. After running the program, you can see that the value after self-increment is still 7, which means that the self-increment is used alone, i++ and ++i, and the results of the two usages are the same.

  4. Anonymous users2024-02-02

    >> can only be used for variables, not for variables.

    Isn't it a question that it can only be used for variables and not constants?

    If this is the case, this is a syntax provision, constants are read-only variables, and directly modifying constants will give an error during the compilation stage, and the variables modified by const are also read-only variables, and modifications are prohibited.

  5. Anonymous users2024-02-01

    What does it mean to be able to use only for variables and not for variables?

  6. Anonymous users2024-01-31

    First of all, both operations are autoincrement operations, and both can only be performed on variables, but there are slight differences between the two types of autoincrement.

    x increments the value of x by 1 first, and then uses the value of x in the current expression.

    x++ uses the value of x in the current expression, and then increments the value of x by 1.

    For example: 1) int x=1; Output 1, x++ first uses the value of x in the current expression, and then increments the value of x by 1,; Output 2, which is incremented by 1 after the previous instruction x is self-incremented

    2)int x=1;;output 2, +x increments the value of x by 1 first, and then uses the value of x in the current expression,; Output 2, which is incremented by 1 after the previous instruction x is self-incremented

    x++ is actually divided into three steps: taking the value, calculating, and assigning the value for example: x=1, x++, in fact, the jvm defines a cache value y y=x; The value (only one time for the closed family) y=y+1;

    Calculate x=y; Assignment and ++x, the steps are different, y=x; Valid value (only once) x=y; Assign y=y+1;Calculation: This is what the book says: x++ is to calculate first and then assign a value, and ++x is to assign a value first and then calculate.

  7. Anonymous users2024-01-30

    The data types of the add++ auto-subtract - operation can be float and double.

    In C, not all variables can use auto-increment and decrement operators; The following data types can be used: int, float, double, char, and long.

    Auto-increment (++) adds 1 to the value of the variable, and is divided into prefix (e.g., ++i) and suffix (e.g., i++) prefix is to add 1 before use; The suffix is used first and then 1.

    Self-subtracting (--subtracts the value of the variable by 1, and divides the prefix (e.g., --i) and suffix (e.g., i--) prefix formulas to subtract 1 before using them; The suffix is used first and then subtracted by 1.

Related questions
27 answers2024-02-09

There are two kinds of self-increment and self-reduction, one is the forward fall (++i,--i), and one suffix (i++, i--) There is a big difference between the two, and the prefix self-increment and self-decrease is to run itself first, and then run others. The suffix is self-incrementing and self-decreasing, which is to run the other first in the run itself. >>>More

6 answers2024-02-09

The more primitive ones are: lime-soda ash softening method, which is not used much. >>>More

6 answers2024-02-09

Reference: It is better to settle the dispute than to settle it, and each of them looks back.

7 answers2024-02-09

Taurus horoscope for this month.

Total fortune. The overall horoscope of Taurus this month is mediocre, you are very much like letting the pace of your life change a little bit, making the original days more interesting, at the beginning of the month some things are not going well, there are many situations, there are endless things, so that you can easily feel tired, but you can only do your best and go with the flow! In the middle of this month, something related to someone else has been hanging in your mind, and if you don't solve it quickly, you can't rest assured, but even though you have reminded the other person many times, the other person still takes your words as the wind in your ears, and you have to go crazy by the end of the month. >>>More

9 answers2024-02-09

The advantage of the brand is that the after-sales service is good, and there is no problem with it. >>>More