Question: The code below compiles well

```
int a=5,b=4,c;
a>b?30:40;

```

Also does,

```
int a=5,b=4,c;
a>b?c=30:40;

```

But why this does not work?

```
int a=5,b=4,c;
a>b?c=30:c=40;

```

Answer: 
You are being bitten by precedence. `?:` has very low precedence, but not as low as `=` or `,` (see the [operator precedence table](http://www.difranco.net/compsci/C_Operator_Precedence_Table.htm)).

Your code is parsed as:

```
(a>b ? c=30 : c) = 40;

```

Rather than:

```
a>b ? c=30 : (c=40);

```

You don't need parenthesis around `c=30` because `?` and `:` act like parentheses to the expression within.

---

Believe it or not, `(a>b ? c=30 : c) = 40` is valid C++ (but not valid C). The expression `(a>b ? c=30 : c)` is an [lvalue](https://en.wikipedia.org/wiki/Value_%28computer_science%29) referencing the variable `c`, to which `40` is assigned.
You've run into a precedence problem with the `=` operator. If you insist on assignment inside of your ternary operator, merely wrap the sub expressions in parentheticals:

```
int d = a > b ? (c = 30) : (c = 40); // explicit precedence

```