cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
Bool - with AM and PM
Bool - with AM and PM
May 16, 2017 at 9:14pm UTC
xxvms
(197)
Hi Guys :)
I am running an example from book and something is puzzling me. I don't understand why code behaves in such way:
bool
pm = hours < 12 ?
false
:
true
;
// find am/pm
I have entered hours as 22, after executing of this line pm flag is changed to TRUE in debugger.
My understanding (well I don't understand the line exactly I think this is the issue)
is as far
choice bool (true or false) PM will be
true
if hours is smaller then 12, or
false
when is bigger then 12.
But it appears its the opposite.
where I could read about this
< 12 ? false : true;
or if someone have time to explain how to read/understand this syntax I would much appreciate :)
thank you :)
May 16, 2017 at 9:33pm UTC
keskiverto
(10402)
http://www.cplusplus.com/forum/articles/14631/
May 16, 2017 at 9:44pm UTC
xxvms
(197)
Keskiverto - thank you!!
That was one excellent explanation.
why I am not correct in reading that if hours is less then 12 it should be false??? :D
hours = 22
PM (hours) is bigger then 12 so it should be read as False????
May 16, 2017 at 10:25pm UTC
keskiverto
(10402)
Another wording:
https://www.tutorialspoint.com/cplusplus/cpp_conditional_operator.htm
Topic archived. No new replies allowed.