Forum Thread: Short C++ Question

Short C++ Question

Hey guys! I'm sorry to probably ask this question. But what does int i = j < 10 ? 5 : 15; mean?

Thanks!,

OT

3 Responses

It's an alternative way to write a conditional statement. If I'm correct, I believe it sets i as an integer variable, then basically says "if j is less than 10, then i equals 5. Otherwise i equals 15." Or in other words:

if ( j < 10 ) {
i = 5
} else {
i = 15
}

correct.

-Phoenix750

Good question and good answer Cracker... I personally don't like to code like this because of this reason.. Unless there are comments being made along the way to make sure everyone looking at the code understands.

Share Your Thoughts

  • Hot
  • Active