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:#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); }
I would've written something like this:Code:{ return x <= y ? x : y; }
Hope I explained myself correctly.Code:{return x = (x<y) ? x:y;}



1Likes
LinkBack URL
About LinkBacks


