Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ Conditional Operator

I once seen a -wired- operator in C++ which assigns value if greater than..
it was a combination of ?, < and =

e.g. let x = value if value is greater than x

I do not mean x=(x<value)x:value

It was some sort of x<?=value

But I can not remember it exactly, and can not find it online... Can some one remind me of it?

Thanks,

like image 413
Betamoo Avatar asked Jul 27 '10 19:07

Betamoo


People also ask

What is conditional operator give example in C?

Syntax of C programming conditional operatorputs("x is greater") : puts("y is greater"); Here, if x > y then puts("x is greater") else puts("y is greater") . The output of both expressions is same.

What is the syntax of conditional operators?

The conditional (ternary) operator is the only JavaScript operator that takes three operands: a condition followed by a question mark ( ? ), then an expression to execute if the condition is truthy followed by a colon ( : ), and finally the expression to execute if the condition is falsy.

Which are conditional operators?

The conditional operator (? :) is a ternary operator (it takes three operands). The conditional operator works as follows: The first operand is implicitly converted to bool . It is evaluated and all side effects are completed before continuing.

What does ?: Mean in C?

The question mark operator, ?:, is also found in C++. Some people call it the ternary operator because it is the only operator in C++ (and Java) that takes three operands.


1 Answers

There is no operator that assigns variables based on their relative values.

However, there is the ?: operator:

x = value > x ? value : x;

If you read it out loud from left to right, it makes sense.

like image 180
Mike Caron Avatar answered Oct 18 '22 02:10

Mike Caron