# Thread: ternary operation with compound instruction

1. ## ternary operation with compound instruction

Hello guys.
By the specification of C I know i can use several instructions (with ) instead of use just one. But is it true if iīm using a ternary operation?
i.e.,
Code:
```x > 10 ? printf( "x > 10\n" ) : printf( "x <= 10\n" ); //valid
x > 10 ? { printf( "x > 10" ); printf( "\n" ); } : { printf( "x <= 10" ); printf( "\n" ) };//question, something like this```
Can you help me (I know my example can be changed in a better way, but itīs just an example!)?

Thanks, Daniel.

2. I suppose you could use the comma operator, but you have to know that it only returns the value of the rightmost expression.
Code:
`x > 10 ? printf( "x > 10" ), printf( "\n" ) : printf( "x <= 10" ), printf( "\n" );`

3. Thanks, but it&#180;s wrong. This way it returned the rightmost expression and returned both other expression inconditionally.

Someone else?

Thanks.

4. Well, may-be you'll need an extra set of parenthesis?

Code:
```#include <stdio.h>
int main()
{
int a = 5;
int b = a > 4 ? (printf("More than 4\n"), 1) : (printf("Not more than 4\n"), 2);
printf("&#37;d", b);
return 0;
}```
Anyway, it might be actually clearer as a if...else expression.

5. A passing thought on the matter:
Code:
```#include <stdio.h>

void foo(int x, int y)
{
printf("&#37;d %s %d\n", x, x < y ? "<" : ">=", y);
}

int main ()
{
foo(5, 10);
foo(15, 10);
return 0;
}

/* my output
5 < 10
15 >= 10
*/```

6. thanks. itīs good! but itīs sounds strange, doesnīt? it might be
Code:
`{ ... }`
, hence "where thereīs 1 instruction you can put 1 or more in that place."...

Thanks

7. Braces are for code blocks with their own scope. I don't believe any operator (including ? allows it's operands to be blocks of code.

But there is such a comma operator and it must have some use.