High score questions about self addition and self subtraction in VC 6 0

Updated on technology 2024-03-08
21 answers
  1. Anonymous users2024-02-06

    Prefix self-addition and suffix self-addition are different, and prefix self-addition is used after self-adding, such as printf("%d,%d",++d,d);Here, although the calculation time is from right to left, when calculating to ++d, the computer explicitly calculates the value of d first and then uses it, and the suffix self-addition uses the additional one, so printf("%d,%d",c,c++) after the compilation result, the printf function uses a value that is 3, because it is used first, which is the result of the compiler's processing. You can only ask the person who designed the compiler in the first place.

    Why is C calculated from left to right) is wrong, not from left to right. I don't believe you can try this with this, printf("%d,%d,%d,%d,%d",c,c++,c++,c++,c++)

    The output is the same as 3,3,3,3,3

    As for the compiler, just pay attention to the programming yourself.

  2. Anonymous users2024-02-05

    printf("%d,%d",c,c++)printf function formats the output data according to the format given by the specified string, so it outputs from left to right.

    The crux of this problem is: C++ overloads the operator, in cout" and the operator returns the ostream& object, first call the operator<<(a++) in the call <

  3. Anonymous users2024-02-04

    The first result was 43, and I really don't really understand.

    For the third one, which is actually related to the compiler, + is generally understood in the back as the first execution and then calculation, + in the front is generally understood as the first calculation and then the execution.

    However, it is not recommended to write this way in actual programming, as it will cause difficulty in understanding.

  4. Anonymous users2024-02-03

    To put it simply, the cout read argument is read from right to left, while printf is read from left to right.

  5. Anonymous users2024-02-02

    Mainly because cout is a right-to-left operation, that is.

    The first line was originally to calculate a++ first; However, if the ++ operation is used first and then added, then the output of the latter one is 3

    And the previous A is actually the result of ++;

    In the second line, the same is true, cout<<+b "I suspected you were wrong when I was hehe, the third line outputs: the first one is of course 3, and the second one is output first and then added.

    The output of the fourth line, it's hard to say, and I'm not sure because I think it should be output 4, 4.

  6. Anonymous users2024-02-01

    The first line of results is explained:

    int a=3;

    cout, so the above operation is: 6 6 5 5 4 4 3

    The third line of the result is explained:

    Another thing to keep in mind when using the printf function is the evaluation order in the output table columns. Different compilation systems are not necessarily the same, and can be left to right or right to left. Turbo C is done on a right-to-left basis. Let's take a look at the following two examples:

    Example 1: main(){.}

    int i=8;

    printf("%d %d %d %d %d %d ",++i,--i,i++,i--,i++,i--).

    Example 2: main(){.}

    int i=8;

    printf("%d ",++i);

    printf("%d ",--i);

    printf("%d ",i++)

    printf("%d ",i--)

    printf("%d ",-i++)

    printf("%d ",-i--) Running Result:

    The difference between the two programs is that they are output with one printf statement and multiple printf statements. But as can be seen from the results, it is different. Why are the results different?

    This is because the printf function evaluates the quantities in the output table from right to left. In the first example, the last term "-i--" is evaluated, resulting in -8, and then i is 7 after subtracting 1. Then the "-i++" term is worth -7, and then i is 8 after incrementing by 1.

    Then the "i--" term is worth 8, and then i subtracts 1 to 7. Then find the "i++" term to get 7, and then i will increase by 1 to 8. Then find the "--i" term, i first subtracts 1 and then outputs, and the output value is 7.

    Finally, the first item in the output table column is "++i", and i is incremented by 1 and then output 8.

    However, it is important to note that although the evaluation order is right-to-left, the output order is still left-to-right, so the result is the output as described above.

  7. Anonymous users2024-01-31

    printf("%d\t %d\t %d\t %d\t %d\t %d\t %d", i, +i, i, +i, -i, -i++,i--)

    in the compiler.

    This is the same as the one below.

    printf("%d\t %d\t %d\t %d\t %d\t %d\t %d", i, +i, i, +i, -i, -i, -i);Note that the value of -when - is given to a temporary variable.

    i--;However, in the following two sentences, the compiler will execute the parameter values in advance after pressing them into the stack.

    i++;Therefore, this expression method is used as little as possible, and it has some relationship with the compiler, which may be different for each compiler.

  8. Anonymous users2024-01-30

    Why do I think the same as yours, I can't explain it.

    But it feels like printf is doing it.

    If include

    int main()

    That's exactly what we thought.

  9. Anonymous users2024-01-29

    Problems with the compiler... 6 6 5 5 4 -4 -5 C-free output is the one you calculated.

  10. Anonymous users2024-01-28

    i--This format has a lower priority than ",", so it is executed at the last step of the statement, and the priority of the operator in vc++ is very important, and the landlord can take a closer look at the book.

  11. Anonymous users2024-01-27

    Actually, you don't understand that the comma operator is the same as the self-added rule, and the comma operator is the rule of operation.

    Multiple expressions are separated by a comma, where the value of the expression separated by the comma is settled separately, but the value of the entire expression is the value of the last expression.

    a=1,b=2 ,c=3;This is the comma expression d=(a++,b,c) ; This is the comma operator you wrote in y=1,y+g,y++; It's not a comma operator at all, it's just a comma expression.

    It's no different from writing 3 times apart.

    Self-addition and self-subtraction are only possible in expressions.

    There is no order to take it out individually.

    There is no difference between y++ and ++y when used alone, and it is different when you put it in an expression.

    int a=5;

    a++;printf("%d",a);

    The result of the output is 6

    int a=5;

    a;printf("%d",a);

    The output is still 6

    int a=5,b;

    b=++a;

    printf("%d",b);

    The result of the output is b=6 a=66

    int a=5,b;

    b=a++;

    printf("%d",b);

    The result of the output is b=5 a=6

    In fact, the self-imposed problem can be simply understood as:

    b=a++;Actually, it is.

    b=a;a=a+1

    b=++a;Actually, it is.

    a=a+1b=a;

    When a++ and ++a

    Not participating in other operations is just a=a+1.

    Also, y++ y alone is y=y+1, and the result is no different.

    Replace "with ++y" in your expression, and the result is the same as y=, which is different in the expression.

    For example, y=1

  12. Anonymous users2024-01-26

    y=1,y+5,y++;

    First of all, y = 1, y is equal to 1.

    y+5, the value of y does not change, and y is still equal to 1

    y++, y self-adding, y equals 2

    The order of operations is after =.

    So you y=1, y+5, y++; The statement is not consistent with what you meant.

  13. Anonymous users2024-01-25

    Y is 2 of course. Comma expressions are evaluated sequentially from left to right.

    y=1; // y=1

    y+5 and y value don't matter.

    y++;//y=2

    If so, s=( y=1,y+5,y++ then the value of s is indeed 1

  14. Anonymous users2024-01-24

    I'm going to use general programming ideas, not specifically VC++

    **Written in an event such as click, it will only be executed once at click, and the variable change will not trigger the second click, so it will not be executed a second time;

    You can consider using a timer to trigger the detection of a variable, and then modify the color according to the value of the variable, for example, the value of the variable is detected once every second, so that it will be executed every second;

    There doesn't seem to be a good way to find a real-time listening event to detect color changes or variable changes, so consider it, as if the textbox value changes and it will be listened to. It would be nice to have an event like OnColorchanged (on the surface), but the underlying implementation is nothing more than a clock-triggering.

    If you don't understand, just ask.

  15. Anonymous users2024-01-23

    You can try using a timer to get the value of the variable at a regular time, and then refresh the state of the indicator. Or if you write the value of the modified variable, that is, you know when the variable was modified, then send a message to refresh the state of the indicator when the variable value is modified.

  16. Anonymous users2024-01-22

    What is the indicator practical for? If it's a control, updatadata(false) try. You didn't update because you didn't send a message to the indicator to update the color.

  17. Anonymous users2024-01-21

    Mr. Tan Haoqiang's C language programming book has the following programs:

    j=5;q=(++j)+(j)+(j);printf("%d",q);

    The result is 24 in Turbo C (in the same book) and 22 in VC++.

    This means that when compiling in turbo c, the whole line will be read, and Q will be calculated after 3 ++J are calculated;

    vc++ first calculates the first two ++j (the addition of the first step of addition), then adds, then calculates the third ++j, and then calculates the q value.

    For testing purposes, change the program to:

    j=5;q=0+(+j)+(j)+(j);printf("%d",q);

    The result remains the same, i.e. vc++ is still the first two ++j (the addition of the first two steps of addition).

    Change to j=5;q=j+(+j)+(j)+(j);printf("%d",q);

    In Turbo C the result is 32 (4 8s added) and in VC++ the result is 27 (6+6+7+8), then VC++ processes the addition of the first step of addition.

    The full guess is as follows:

    Turbo C is compiled by reading the entire line and then computing;

    VC++ is a step-by-step calculation, similar to the four-rule operation method with a stack, and the first two variables are not pre-read.

  18. Anonymous users2024-01-20

    The order in which the expressions are evaluated, so that each compiler handles these subexpressions differently, so the first result is unknown.

    The result of the second one is very clear, the prefix is added to get 6, and the prefix is subtracted to get 5, and the result is 30.

    The final result of the third one is still self-subtracting twice, so it is 4, but the value of the intermediate expression is also unknown.

    Therefore, this type of expression should not be like the first.

    One or three like that, the result will be inexplicable, and the second one has no ambiguity In addition, the product on the virtual machine group is super cheap.

  19. Anonymous users2024-01-19

    The order of comma expressions is right first and then left, so in the first printf, the expression (a--)a--)a--)a processes the right a first, so it outputs 4, and then the left (a--)a--)a--)a---)a---a-a--a-a

  20. Anonymous users2024-01-18

    The arguments in the printf() function are output from right to left.

    printf("%d,%d",(a--)a--)a--)a);For example, output a first, and then compute (a--)a--)a--) output.

  21. Anonymous users2024-01-17

    1. In C language, posterior self-increment (self-decrease) means that the value of the variable is self-incremented (self-decreased) after the execution of the statement.

    2. Examples are as follows:

    int num=0, s=0;

    while(num++<3)

    When the first while is executed, num=0, after the first while is executed, num=1, in this case, s=0+1=1

    When the while is executed for the second time, num=1, after the while is executed for the second time, num=2, and in this case, s=1+2=3

    When the while is executed for the third time, num=2, after the while is executed for the third time, num=3, and in this case, s=3+3=6

    On the 4th time while is executed, the loop is pushed out because num=4>3, and finally s=6

Related questions
3 answers2024-03-08

If you want the source**, I can make one and send it to you. >>>More

4 answers2024-03-08

The system is messed up, so let's reinstall the system first.

8 answers2024-03-08

The reason for the problem is the difference between ANSI and Unicode encoding of strings, VC6 and VS2003 use ANSI encoding by default, while VS2005 uses Unicode by default >>>More

14 answers2024-03-08

I also have a bad stomach, and I found that yogurt and milk are good for people who have a bad stomach and can't eat strong acid foods such as lemons or anything and don't eat foods that produce a lot of calories after digestion, dryness, and heartburn is very uncomfortable >>>More

15 answers2024-03-08

No play, EK only guarantees that it will not be found under the slit lamp examination, but because the laser cutting range is not very large, generally only a circular area of diameter, although it is larger than the usual pupil size, it will not affect the light convergence, but once the pupil is dilated, the pupil size is far greater than the surgical cutting range. When the pupils are dilated, the retina will not be able to concentrate light accurately (your visual perception will be severe glare, i.e., there are many thorny "light spines" near the light source, so that you can't see at all). Even if you don't say how you feel, the doctor doesn't need much experience to examine your eyes, take a small light source, look for your eyes, and observe the convergence of light on the retina of the fundus, because the surgical area is narrow, there will be two spots with different focal lengths on the retina, and they cannot converge at the same time. >>>More