Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.
This conditional operator is a little stranged and it's the only one operator with operate three expresions.
Ternary operator is used to substitute code below for example:
int max, a, b;
if (a > b) // if condition is true do it
{
max = a;
}
else // if condition is false
{
max = b;
}
with ternary
max = (a > b) ? a : b;
in this case if a > b are true then max = a, if not max = b
it has the format:
exp1 ? exp2 : exp3;
if exp1 is true the result is exp2, if false the result is exp3
= is used to attribute values
== is used to compare
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.