Hello, welcome to the 15th tutorial in the c++ programming series, and in this part, we're gonna be looking at the conditional ternary operator, the conditional ternary operator allows you to check an expression returns one value if the expression is true. And another if the expression is both very similar to an offset with something that we haven't covered here. But we will be covering soon in the next few tutorials or in a few tutorials I should say. Personally, I prefer the if statement, I will literally never use conditional ternary operator, just because I prefer the look of this demo. And you'll see what I mean if if you Google it, or if you just wait a few tutorials. Plus, every time I've ever seen anyone use some sort of a condition.
They've always do this statement. Every person I've ever seen use they never use the conditional ternary operator. Generally due to the syntax, it is a lot simpler or it's not a lot neater which will take a dump It looks neater, it's more compact. And it's definitely more suited if the conditions are very simple conditions more conditioned. And it's very easy to fit on one line. But let's just go ahead and show you what the condition ternary operator looks like.
Okie dokie, what we can do just quickly remove the existing code we're going to do is for equal equals five. So basically you put your condition here, okay, little four equal five. He doesn't but that's the condition they do. Sent I mean upset. Little words, that's a question mark. Then you put the value that you would want to basically return if this condition was true, but to and then coal on one If well it's not true obviously we can assign this to something totally new in reload equals So what we're going to do is just see the result Mr. T the angle brackets STD new line or a line that it's a runner going to open up the debug area Okay so we've got one return plus four doesn't equal five but if we do for their, their returns to or it signs the result to the integer result aka two then it prints out two in literally they did nothing but obviously you can do any of these any for any one of these four can be variable.
They don't all have to be variables doctor just Do the equals one, you can do make the greater than we looked at it in the previous tutorial, the tutorial for that's the 30 tutorial relation and comparison operators, if you can use any of them to reduce do is for greater than or equal to four? If so it will print out two is for greater than or equal to say what do you think your print print out one because not greater than it's not equal to but if we've got three is greater than three not equal to but is greater than seven, we'll print out two. And yeah, they obviously you can, like here, maybe do some mathematical functions. So if we run that, it returns one because it does three plus five, which is eight, is four greater than or equal to eight? No, so we put one in the integer result.
Yeah, that's it for this tutorial. If you have any questions, feel free to message us. Support us on the system. Correct. Okay. The email will be in the scription you can comment on this video or just directly messages via YouTube whatever you feel comfortable with.
The order requirement for source code will also be in the description. In the next tutorial we'll look at the comma operator. And as usual, thanks for watching and I hope you have a nice day.