Author Topic: C Programming Syntax  (Read 1787 times)

0 Members and 1 Guest are viewing this topic.

Offline Ground_LoopTopic starter

  • Frequent Contributor
  • **
  • Posts: 644
  • Country: us
C Programming Syntax
« 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?
There's no point getting old if you don't have stories.
 

Online oPossum

  • Super Contributor
  • ***
  • Posts: 1415
  • Country: us
  • Very dangerous - may attack at any time
Re: C Programming Syntax
« Reply #1 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;
 

Offline Ground_LoopTopic starter

  • Frequent Contributor
  • **
  • Posts: 644
  • Country: us
Re: C Programming Syntax
« Reply #2 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.
There's no point getting old if you don't have stories.
 

Online DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5896
  • Country: es
Re: C Programming Syntax
« Reply #3 on: December 02, 2021, 05:56:54 am »
For sure, the "?" is missing, if you try that syntax it will cause a compiling error.
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf