N
Nicholas M. Makin
I was just thinking that I understood the conditional operator when I coded
the following expecting it to fail:
int a= 10, b= 20, c= 0;
((a < b) ? a : b) = c; // a=0
a=20; b= 10;
((a < b) ? a : b) = c; //b=0
Now since the expresion 5 = c is not valid I did not expect the above to
work. But it does work. Why? I thought that the ?: operator would evaluate
to the value of "a" or "b" not to some kind of pointer to the value. This
really leaves me wondering how the operator works.
the following expecting it to fail:
int a= 10, b= 20, c= 0;
((a < b) ? a : b) = c; // a=0
a=20; b= 10;
((a < b) ? a : b) = c; //b=0
Now since the expresion 5 = c is not valid I did not expect the above to
work. But it does work. Why? I thought that the ?: operator would evaluate
to the value of "a" or "b" not to some kind of pointer to the value. This
really leaves me wondering how the operator works.