As my fledgling programmer brain has finally started to grasp pointers and the like, the nuances of C syntax are beginning really to intrigue (if baffle) me.
My question:
While fiddling with the dreaded ternary operator, I figured out that the following works
I'm not wildly surprised that some variation of the above worked, but a few questions about the fact that it does: I thought the ternary operator evaluated the second and third operands as expressions, which function calls are not...right?Code:int x=2; (x==2)?printf("yay!\n"),printf("Whee"):printf("boo");
Also, why don't these calls need semi-colons; does that semicolon in the end in fact get pasted onto the end of the expression? (I think that would be a cute nuance of the operator. (I also think it's cool thatworks. Why don't textbooks mention this? Or is it particular to my compiler?))Code:printf("foo"),printf("foo2");
In fact, maybe it's just a highly unportable expression that happens to work on my compiler, and these questions have no one answer. Thoughts?