EEVblog® Electronics Community Forum

Electronics => Microcontrollers => Topic started by: Ground_Loop on December 01, 2021, 06:53:25 pm

Title: C Programming Syntax
Post by: Ground_Loop on December 01, 2021, 06:53:25 pm
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?
Title: Re: C Programming Syntax
Post by: oPossum on December 01, 2021, 06:57:28 pm
I think there is a question mark missing.

Code: [Select]
A = (B < C) ? D : E;

That would be a ternary operator.

Equivalent to..

Code: [Select]
if (B < C)
  A = D;
else
  A = E;
Title: Re: C Programming Syntax
Post by: Ground_Loop on December 01, 2021, 07:05:56 pm
I was thinking the same, but there is definitely not a question mark.  I'll consider it a typo.
Title: Re: C Programming Syntax
Post by: DavidAlfa on December 02, 2021, 05:56:54 am
For sure, the "?" is missing, if you try that syntax it will cause a compiling error.