Labels: different C languages using Ar c Algorithm Application har
Many programs written by Daniel often see if (0 = x) {execution body}, while self-written programs often use if (x = 0) {execution body }. At the beginning, I was confident that this expression was equivalent, just to show off a distinctive style. When I read the C language calculation method, this part of the content will suddenly understand the comprehensive consideration of Daniel. The analysis process is as follows:
The combination of the "=" operator is the combination of the right (from the right to the left) "=" operator is the combination of the left.
0 = I the format of the error 0 = I and I = 0 is the same.
Do you understand this. If (0 = I) is written to prevent "=" from being written as "= ". If you accidentally write "=" as "="
If (x = 0) is used to write the statement, it is converted to If (x = 0). Even if an error is written, the compiler will not report an error. If it is written in the form of IF (0 = x), if (0 = X), the compiler returns an error. Error c2106: "=": The left operand must be the left value.
Write a program to test:
// Test_zeroeqx.cpp: defines the entry point of the console application. // # Include "stdafx. H "int _ tmain (INT argc, _ tchar * argv []) {int x = 0;/* Daniel's Writing Method */If (0 = X) printf ("x = 0"); else if (0! = X) printf ("X! = 0 ");/* when x = 0 is written as x = 0, the normal execution result of the program is x = 0 x! = 0 */If (x = 0) printf ("x = 0"); else if (X! = 0) printf ("X! = 0 ");/* remove the comment and you can see that x = 0 returns the false value * // * bool iszero; iszero = (x = 0); If (iszero) printf ("x = 0 returns false") else printf ("x = 0 returns false"); */getchar (); Return 0 ;}
From the test procedure, x = 0 returns false. If you write "=" accidentally "=", it is difficult to find errors if you follow the average person's instructions. Rather, the compiler reports an error directly.
Logic Operations 0 = x and x = 0