Continue to Site

Welcome to EDAboard.com

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.

Why do we use ternary operator in C?

Status
Not open for further replies.

vimal2010

Banned
Joined
Sep 14, 2005
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
0
why do we use ternary operator in C?whats its significance?whats the difference between = and == in C?
 

Re: ternary operator?

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

leomecma
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top