Can someone explain this syntax?

Sorry for the noob question, but I looked around and couldn't find an explanation. What does the following assignment do?

dig[0] = h/10 ? h/10 : 10;

(h is the time in hours, between 1 and 23)

specifically what does the ? and : represent?

Thanks for your assistance!

It's basically an if / else.

if h/10 digit[0]= h/10 else digit[0] = 10

Its called a "ternary operator"

If you search for 'C++ ternary operator' you will get more than you need.


It is also a rather slow way to check if h is greater than 10. I would have used >= operator. It will be dozens to hundreds of times faster than this, not to mention more understandable.