Explanations of a=0 and a==0:
if: int a = 0;
So a=0 this expression is false, a==0 this expression is true.
if: int a = 1;
So a=0 this expression is false, a==0 this expression is false.
As an example:
int a = 0; if (a = 0) printf ("True"); else printf ("False");
output: False.
<span style= "FONT-SIZE:18PX;" > </span><span style= "font-size:10px;" >int a = 0; if (a = = 0) printf ("True"); else printf ("False");</span>
output: True.
int a = 1; if (a = = 0) printf ("True"); else printf ("False");
Output: False
int a = 0; if (a = 1) printf ("True"); else printf ("False");
Output: True
An example of combining the C-language precedence with the binding:
int main () { int a,b,c; a=b=c=0; (1>0?a==0:0>1)? b++:c++; printf ("%d%d%d\n", A, B, c); return 0;}
The output is: 010.
int main () { int a,b,c; a=b=c=0; (1>0?a=0:0>1)? b++:c++; printf ("%d%d%d\n", A, B, c); return 0;}
The output is: 001
int main () { int a,b,c; a=b=c=0; 1>0?a++:(0>1?b++:c++); printf ("%d%d%d\n", A, B, c); return 0;}
The output is: 100. It is strange that the values of B and C have not changed. In C, conditional expressions: The binding is right-associative (that is, the right-to-left combination). This is the same as the following program:
int main () { int a,b,c; a=b=c=0; 1>0?a++:0>1?b++:c++; printf ("%d%d%d\n", A, B, c); return 0;}
The parentheses are removed. The output is verified exactly the same: 100.
Then, the precedence of this bracket () is much higher than the precedence of the conditional expression. So it should be calculated first (0>1?b++:c++) this right? Isn't it?
If yes, then 0>1 is false, then execute C + +, so c=1;
If not, then take the back bracket (0>1?b++:c++) as the front?: A subkey of the statement. Then the first Judge 1>0 is true, so execute a++,a=1; answer output 100. Correct!
Is it like this?? Let's verify it again:
int main () { int a,b,c; a=b=c=0; 0>1?a++:(0>1?b++:c++); printf ("%d%d%d\n", A, B, c); return 0;}
The output is: 001. Analysis, first Judge 0>1 is false, so execution (0>1?b++:c++), judgment, 0>1 for false so execute c++,c=1; output 001, so the hypothesis is verified.
That should be the case at the moment.
Let's look at an example:
int main () { int a,b,c; a=b=c=0; 0>1?a++:0>1?b++:c++?1>0?b++:c++:a++; printf ("%d%d%d\n", A, B, c); return 0;}
The output is: 101.
C Language study-a=0 and A==0