int main()
{
int i, c;
i:
for (i = 0; i < 3; i++) {
c = i &&&& i;
printf("%d\n", c);
}
return 0;
}
The output of the above program compiled using gcc is
0
1
1
How is c evaluated in the above program?
The use of labels as values is a
gccextension (see here). Your expression segment:equates to:
c = i && (&&i);
where
&&iis the address of the labeli.Keep in mind you’re combining two totally different
i“objects” here. The first is theivariable which cycles through0, 1, 2, while the second is the labeli, for which the address is always some non-zero value.That means that the result placed in C will be
0(false) only when the variableiis0. That’s why you’re getting the0, 1, 1sequence.