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.

Simple C Statement, Probably "if" syntax

Status
Not open for further replies.

w_bwr

Member level 3
Member level 3
Joined
Feb 4, 2010
Messages
66
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
Karachi, Pakistan
Activity points
1,810
Code:
ucN2RateKFlg = (ucN2RateKFlg >= 7) ? 1 : (ucN2RateKFlg + 1);

This is a C code. What does this implies?
 

? : Operator

The ? : operator is just like an if ... else statement except that because it is an operator you can use it within expressions.

? : is a ternary operator in that it takes three values, this is the only ternary operator C has.

? : takes the following form:

Code:
if condition is true ? then X return value : otherwise Y value;

https://www.tutorialspoint.com/ansi_c/c_control_statements.htm
 

It's called a conditional operator.

(ucN2RateKFlg >= 7) is evaluated, then if true, the first operand ofter the ? is returned, otherwise the second (after the : ) is returned.

The result is finally stored in ucN2RateKFlg because of the ucN2RateKFlg =

So, if (ucN2RateKFlg >= 7) is true, 1 will be returned and stored in ucN2RateKFlg otherwise (ucN2RateKFlg + 1) will be returned and stored in ucN2RateKFlg
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top