# Simple ternary operation baffling me

• 02-20-2012
alter.ego
Simple ternary operation baffling me
Code:

```#include <stdio.h> #include <stdlib.h> inline int min(int x, int y) { return x = y ? x : y; } int main(int argc, char** argv) {     int x = 1;     int y = 15;     printf("x=%d,y=%d\n", x, y);     printf("min(x,y)=%d\n", min(x, y));     return (0); }```
While Googling for some stuff I chanced upon above code. My idea of Ternary operation is in slight doubt. In code below I don't see any comparison.

Code:

`{ return x <= y ? x : y; }`
I would've written something like this:

Code:

`{return x = (x<y) ? x:y;}`
Hope I explained myself correctly.
• 02-20-2012
laserlight
The comparison is x <= y. If you really saw x = y, then it is probably just a typographical error.
• 02-20-2012
Tibo-88
In C, in order to compare two values, you must use the "==" operator. The "=" operator is used for assigning values.

Then the second code has comparison, the literal translation would be : "is x less than or equal to y? if yes, return x, otherwise return y".

Hope that helps.
• 02-20-2012
alter.ego
@laserlight @Tibo-88: Thanks for quick revert. It was not typo; I was flummoxed seeing expression "x<=y" in ternary operation. But thanks for clarifying.
• 02-20-2012
Subsonics
Using the '<=' operator is confusing in this case IMO because the function name is min() and the result is the same regardless, because if 'x == y' it does not matter which one is returned.