Hello and welcome to the 20th tutorial in the c++ program series and In this problem, we are looking at operator precedence. different operators are operated the multiplication operator as the minus operator, the brackets, the indices, central etc. Basically a lot of the stuff that you've operated, searching precedence over aka they have higher priority. And we're just going to go to Google and just show you some of the operator precedence I want to invite higher priority is you might type in this a little formula, mathematical formula. And you might look at NSU mentally from left to right, whereas he doesn't he would do based on operator precedence. So if the operator at the right that has higher precedence than the ones on the left, then he would do that operation first.
And that does affect the result in pretty much every situation. So that's something to bear in mind and the way to get older. By using brackets as in a mathematical sense, but as a show you the operator precedence, so right. precedence plus plus this is what we saw one. Yep, this is great. So yeah, this is just got a simple table and it will show you which operators have higher precedence.
So the scope resolution Okay, the colon colon, when you're accessing stuff when namespace has the highest precedence then after that is stuff like bracket is plus plus minus minus is accessing by reference and pointer. And what else do we see a multiplication and the other one so yeah, we're going to deal with these and but it's very similar for only a little look, it says multiplication had the higher precedence than the plus. So what we're going to going to open up our project give you like a really quick example of this. We're actually not going to provide a source code for this simply because doesn't really need any, any because of so many operators. We're not always going to be doing every single situation for pretty much important infinite number situation. This is more just something that you will want to refer to alias or for some other website, we're going to do int, what is low float equals five plus six times two.
So if you had to do it from a per interval, right, if you were to do it from left to right, you would do four plus six is 11. Number two, which is 22. Whereas it won't do it in terms of operate presses. So we will do the multiplication first. So six times three, which is 12 plus five, which is 17. So instead of it being 22 results should be 17.
So let's just see this and get results 17. If we were to put brackets on this because that has even higher precedence than the multiplication, as you will remember, we got the mathematical operators here and we got the brackets right there. So that's literally one of the highest precedence. Now if we run it, we get a result 220 so we can easily get around operator precedence using brackets which is great because you might not want the operator the general operator precedence. I and my group of friends that code we generally always use operated quite a lot simply because he just helps us to Be certain that this piece of code that we want to run first or run last will run in the order that we want to run. Sometimes it can go low cranium bracket.
Try not to do that they can get a little confusing with a lower nested bracket. But yeah, that is literally for this tutorial on operator precedence. If you need more information, just Google it, or actually there'll be a link in the description to that webpage that we just visited. Plus, you can comment on this video directly messaged us via YouTube or you can email us as well as on our system coda UK. email will be in the description that we know so code as I just mentioned, in the next tutorial, we'll be covering string strings. And as usual, thanks for watching and hope you have a nice day.