-
The difference between i++ and ++i is also in the for loop;
i++ means to use the value of i first, and then give i+1Because you need to use the value of i first, i++ is actually a new temporary variable tmp i;
Then execute tmp i = i; Then use the value of i, and then assign the value of i: i = tmp i+1. So i++ is not as efficient as ++i.
i means to do i = i +1 first; Then use the value of i.
Then, depending on the situation, if i actually has to do something other than just counting, such as positioning. Then i++ is suitable; If it's just for counting or controlling the number of cycles, it's a little more efficient to use ++i. Personal humble opinion.
-
There is a difference. i++ is to take the value of i to participate in the operation first, and then make i+1. ++i, on the other hand, is the opposite of i, i first +1 and then takes the value of i to participate in the operation.
e.g. int i=10;
int qq=i++;
Here, because the value is taken first, and then +1, so;
int ss=++i;
Because 1 is added here, and then the value is taken to participate in the operation, so ss=11
-
for(int i=0;i<10;i++) does not involve operations on i}for(int i=0; i<10;i++) does not involve operations on i}for(int i=0; i<10;){i++;or ++i} the above three equivalents.
That is, the for statement is always executed after the loop body (statement 1; Statement 2; Statement 3).
-
There is a difference, there is a difference in the number of executions. Hope it helps.
-
There is no difference Proven in practice.
-
for(i=0;The process of its execution is as follows:
First, assign an initial value of 0 to the variable i, and then judge that if the condition i<2 (yes) is satisfied, the statement of the loop body is executed, and then i++ after completion, i.e.
i = i + 1。
i becomes 1, and then it is judged again whether the condition i<2 (still) is satisfied, and then the statement of the loop body is executed, and then i++ is completed, i.e.
i becomes 2, and again judges whether the condition i<2 is satisfied, and finds that it is no longer satisfied, so it exits the loop.
The 1 in the middle of the for loop is always true, so it's an endless loop (unless i exits the loop with break when a certain condition is met), i starts at 0 and adds one to each loop.
When i=0;Judging i<10, i++ is retained and accumulated in a loop. When i=9<10, 9 is retained, when i=10, it is judged that i<10 is wrong, and the previous cannot be passed, i++ does not happen, so neither 10 nor the cycle is retained. i=9 is the last value.
The C language contains only 9 kinds of control statements, only 32 keywords, and the programming requirements are not strict and mainly lowercase letters, and many unnecessary parts have been simplified.
In fact, the composition of statements is less related to hardware, and the C language itself does not provide hardware-related input and output, file management and other functions, if you need such functions, you need to program through various libraries supported by the compilation system, so the C language has a very concise compilation system.
C allows direct reading and writing of hardware memory addresses, so that the main functions of assembly language can be realized, and the hardware can be directly manipulated. C language not only has the good characteristics of high-level languages, but also contains many advantages of low-level languages, so it has a wide range of applications in the field of system software programming.
-
It is a circular statement that will be executed twice (in the case of i=0 and i=1, respectively) (Note: The following is **, no punctuation.) )。
#include
int main()
int n,m,i;
scanf("%d %d",&n,&m);
for(i=0;iif(i>m) break;
for(;i{printf("%d",i);
return 0;
This is that the initial value of variable i is 0, and when the value of variable i is less than the value of variable n, it enters a loop, and then variable i increases itself, and when it reaches n-1 (the previous value of n), it jumps out of the loop.
First, the initial value of 0 is assigned to the variable i, and then it is judged that if the condition i<2 (yes) is satisfied, the statement of the loop body is executed, and then i++ is completed, that is, i = i +1; i becomes 1, and then it is judged again whether the condition i<2 (still) is satisfied, and then the statement of the loop body is executed, and then i++ is completed, that is, i becomes 2, and the condition i<2 is satisfied again, and it is found that it is no longer satisfied, so it exits the loop.
There can also be contradictions in the C language:
c stipulates that && has a higher priority than ||
c optimization: If exp1 is false in exp1 && exp2, the value of exp2 is no longer calculated.
c optimization: in "exp1 ||exp2" If exp1 is true, the value of exp2 is no longer calculated.
According to the regulations, &&& needs to be calculated first, that is, ++b and c++ need to be calculated.
According to the optimization, as long as a>0 is calculated, there is no need to calculate ++b and c++.
x=1,y=1,z=1;++x ||y &&z can be said as long as ++x is computed (exp1 ||exp2 &&exp3) and (exp2 &&exp3 ||exp1) will have different results, which is also not in line with lifestyle habits. Could this be "++***".
-
There is a difference between i++ and ++i in a for loop, and the differences are as follows:
i++ is to reference the value of i before adding itself, while ++i is to let i add first and then reference the value of i. In this loop, the output value of trapped rock Xiao i++ is 0 1 2 3 4 5 6 7 8 9, and the output value of ++i is 1 2 3 4 5 6 7 8 9, but after the execution of both algorithms, the value of i is 10In general practice, it is more efficient to add a reference first.
The variables in the for loop can be one or multiple, don't be limited to one variable to deal with it to the end, that can sometimes be very monotonous, when the program is suitable for multiple variables to form a loop, it is a bit of a waste to use multiple for statements to represent it!
for loop considerations:
1. The statement in the for loop can be a sentence body, and the parentheses are added outside the sentence"{} encloses the statement that participates in the loop. The three expressions of the for loop are all comma expressions, so in fact, each semicolon expression can be composed of several comma expressions, and the middle is used", "spaced apart, and finally ended"; "The end.
2. for loop"A single expression"、"Conditional expressions"with"Circular body statements"are all options, i.e. they can be defaulted to "only"; "."The reason why it cannot be defaulted is that the compilation format is like this, and the default compiler does not recognize it and will report an error.
3. When the single expression used for initialization is omitted, it means that the initial value of the cyclic control variable is not assigned.
4. The conditional expression is omitted, and if you don't do anything else, it will become an endless loop.
5. If all the loops are omitted, the for statement will not produce any jujube belt effect when it is not processed by other forms.
-
The main differences between i++ and ++i in a for loop are as follows:
1. The order of citation is different.
The former is: quote first, then increase, and the latter is: add first, quote later, ++i is to change the value of i first, and i++ is to use the i value first and then change its value.
For example, if the original value of i is 5, then for j=++i, the value of j is 6; For j=i++, the value of j is 5, and then the value of j becomes 6.
2. The output results are different.
The two expressions are different, and their output results are also different, i++ output result is 1, and ++i output result is 2.
-
If it's just a single statement, it doesn't make a difference, for example, for(i=0; i<9;i++) and for(i=0; i<9;++i) means that at the end of each f0r cycle, i+1 is used to determine whether i <9 before entering the next cycle. Or i++ inside the loop; and ++i; It's the same thing.
But if it's not a separate statement, there's a difference: for example, n=++i; and n=i++; The value assigned to n is different, the former n has a value of i, i and then +1, and the value of the latter n is the value of i after +1. When the value of one array is assigned to another array, y[j++]=x[i]; with y[++j]=x[i]; There are also different starting points for the start of the y-array.
-
++i is to change the value of i first, i.e. add 1 and then use the value of i.
And i++ is to use the value of i first, and then change its value, i.e., add.
-
To put it the other way, n = ++i means to assign the value of i to n after doing an autoincrement operation
n = i ++ means that the value is assigned first, and then the autoincrement operation is done.
-
i++ and ++i are executed the same number of times in the for loop, so write either way.
-
Of course, there is a difference: one is to add one first and then cycle to the bad, and the other is to cycle first and then add one.
Specific: If it's just a single statement, it doesn't make a difference, for example, for(i=0; i<9;i++) and for(i=0; i<9;++i) means that at the end of each f0r cycle, i+1 is used to determine whether i <9 before entering the next cycle. Or i++ inside the loop; and ++i; It's the same thing.
But if it's not a separate statement, there's a difference: for example, n=++i; and n=i++; The value assigned to n is different, the former n has a value of i, i and then +1, and the value of the latter n is the value of i after +1. When the value of one array is assigned to another array, y[j++]=x[i]; with y[++j]=x[i]; There are also different starting points for the start of the y-array.
When I saw the i7 level on the title, I immediately thought of the whole machine of some unscrupulous stores in a certain treasure that used foreign garbage to pit Xiaobai. At that time, when I saw this i7 level for the first time, I rejected it in my heart, because the 1st generation i7 is also i7, and the 8th generation i7 is also i7, so what level is this i7 level? Generation 1 and Generation 8 are almost worlds apart. >>>More
Both models are 7.2 million pixels, 3x zoom, facial recognition, de-shake, red-eye reduction, PMP, *****, text reading, recording, camera, and scene shooting modes. The frame rate is 20 when the resolution is 800*592, and the maximum frame rate is 30 when the resolution is 600*480 and 320*240. >>>More
Yes, the i5 gaming experience is not so good. >>>More
This mobile phone was launched at the end of last year, and it belongs to the lower-end model of Sony Ai, but the cost performance is still quite high, and if you buy it now, you can get it for about 1000. The two million cameras can still meet the general needs of taking pictures, and at the same time, there is a unique ** repair of Sony Ai, after the repair is done, the **quality is still OK, but there is no own flash, and the shooting effect is not good at night. If you are licensed, you can support phrase input, unlike the previous machine typing that had to come one by one, but now it's faster. >>>More
Upstairs is not kind, can such people understand?
There is no difference between the two, except that there are several networked games built into the 680G. >>>More