Electronics > Microcontrollers

C Programming Syntax

(1/1)

Ground_Loop:
I ran across something similar to this and don't know how to interpret it.     A = (B < C)  D : E;      Of course there were actual numbers and variables, but you get the idea.  What is being assigned to A?

oPossum:
I think there is a question mark missing.


--- Code: ---A = (B < C) ? D : E;

--- End code ---

That would be a ternary operator.

Equivalent to..


--- Code: ---if (B < C)
  A = D;
else
  A = E;

--- End code ---

Ground_Loop:
I was thinking the same, but there is definitely not a question mark.  I'll consider it a typo.

DavidAlfa:
For sure, the "?" is missing, if you try that syntax it will cause a compiling error.

Navigation

[0] Message Index

There was an error while thanking
Thanking...
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod