Hello and welcome to the eighth tutorial c++ programming series and in this part we're gonna look at constants, constants are expression with a fixed value. Go ahead and show you how to implement them. two main ways to implement the mind in a variable manner. One is a hash map, aka will be a preprocessor call. And the first one we can declare variable P and Wilson it declare variable here, but you can do cons inside the main or a function if you want. So we just use the keyword constant constant in the correct data type pool, it's going to put pi equals 3.14159 semi colon.
So this means by this function, all the functions in this class, so rather and what we get is if we just see the st they see COI email notification theory again semi colon now we run it we get it printed out. So you access it and same way as you would a regular variable. But if I try and do pi equal 78 7.9 Rhonda and they fail read only variable assignment basically you can disarm the Assign the data once and that takes obviously say constant but he will give you an error a compiler Or another way you can do it or what else you can do is show you this const sure new line equals backslash Now if we just do new runner, it prints a new line instead of actually point STD colon colon new like, hey, if he was my mother is my value STD colon colon, new line I mean and line and now, but this is another way of doing it and the other way of doing constants are hash define Like I said before, but one thing to be aware of hash defines it as product before everything else.
You can't put it in sorry, the function has to be solid a function so I'm going to put pi as as capital and then let's do 3.14159. You don't specify the type or anything like that. No put a semicolon and then slash define you learn For slash pi, the new runner he gets the same result, but it's slightly different in comparison. So let's just show you what happened if you put inside a function honestly, I've never put it into the function lists now. Fair enough. I never put a patch defined inside the function.
I just said I, I have a new within an estimate my way. But yeah, that's I use constants. You can use the keyword const or you can use hash define thing both of them have their merits. It just depends on also what you feel comfortable with. Plus a we prefer using beads generally a lot more provided. We find that They have a little more flexibility and easy way to distinguish them from from this was to look like a variable.
And so that's it for this tutorial. In the next tutorial, we're going to look at the assignment operator. If you have any questions feel free to message us or support us on our system curry K. The email will be in the description you can come to this video or directly message us via YouTube. Wherever you feel comfortable with all the required links or source code will also be in this in the description. And as usual, thank you for watching and I hope you have a nice day.