Consider this line:
digitalWrite(lampPin, state ? HIGH : LOW);
Can someone point me to the Language Reference that describes what the ? is doing?
Consider this line:
digitalWrite(lampPin, state ? HIGH : LOW);
Can someone point me to the Language Reference that describes what the ? is doing?
Any C++ reference
It is sometimes called the Elvis operator, and the colon is part of it.
a?b:c ;
basically means,
If a is true then the result is b, otherwise the result is c.
?: is a ternary operator (meaning that it takes three operands), possibly the only one in C/C++.
Why is it called the Elvis operator? Because if you look at it sideways and squint a lot, you may see Elvis Presley.
Ternary operator...
https://www.google.com/search?q=c%2B%2B+ternary+operator
Conditional operator...
https://www.google.com/search?q=c%2B%2B+conditional+operator
aarg:
Any C++ reference
Except everywhere I looked from my K&R book to an online search.....
vaj4088:
It is sometimes called the Elvis operator, and the colon is part of it.a?b:c ;
basically means,
If a is true then the result is b, otherwise the result is c.
?: is a ternary operator (meaning that it takes three operands), possibly the only one in C/C++.Why is it called the Elvis operator? Because if you look at it sideways and squint a lot, you may see Elvis Presley.
Thanks- I couldn't remember the name of the operator..
Thanks, also to Vaj. I knew it was a valid operator- I just couldn't remember the name to verify my suspicion of how it works.
SteveMann:
Except everywhere I looked from my K&R book to an online search.....
A little hard to find, but K&R (paperback, 2nd Edition) Page 51.
It is in my 1978 K&R in section 2.11 on page 47.
I googled "c++ operator", followed the first link and it was listed. It will be in any respectable list.
vaj4088:
It is in my 1978 K&R in section 2.11 on page 47.
Amazingly, I still have that one too. It was the text for the introductory C course in college.
My friend Mr Google found 299 results when I searched for "C question mark operator"