 Hello everybody, welcome back to C++ programming. I am Root of the Null and in the last tutorial we were looking at functions that had arguments. We had a very simple very very primitive and kind of basic example which is simply adding and that took a that took advantage of the plus operator, the addition operator in C++ and I'm going to kind of revamp this. I'm going to go ahead and save a copy of my code here and I'm going to rename this to 08 functions with default arguments.cpp. All right so now now that we have this renamed let's change up this function. Let's say int says who I'm going to actually make that void a void says who and let's have a character name which can only be one letter or so yeah person let's let's try to be care person I'm stuttering I'm making a fool of myself the character person or char and has a int age now you'll notice that I typed the equal sign here I was using an assignment operator and what that will do is it will set this argument age to be optional it will have a default setting by default age can equal anything we tell to be it can equal 0 age 20 and then let's just go okay c out person person age age says hello this person yeah whatever we pass person a person b person c person d person x whatever and you can have any age which by default will be zero like we know we'll say hello so now if I run says who inside of the main function we need a person that's a mandatory argument it does not have a default value says who let's say a now if I run this code I'll get over to my terminator g plus plus oh eight let me just clear the screen here and a dot out all right I got an error here what's going on all right that's a pretty simple one I just forgot my semi colon before the return zero in the main function okay now let's get over here oh I got another problem again I just forgot the semi colon before the end of this function here and says who after c out actually let's add an end line over at the bottom here okay now we can run the code hopefully nope another problem okay I see the problem um this is kind of something that's we'll have to get we'll have to hint on in the future as we move on in my says who call in the in the main function I use two apostrophes for the quotation marks I use two quotations we want to use a single quotation and the quotation marks because since this is just a single character c and c plus plus would much rather it be a single character with the single quotation mark rather than multiple quotations with two quotation marks which could refer to a string which is not what we mean we mean a single character so that's why it wants to use only a single quotation mark that's through its quotation marks now if we run the code now it works okay person a age zero says hello okay cool it by default it's going to see that age is equal to zero although we can pass in a value for it we can say person a is age 30 right person a age 30 says hello that works well they could have a negative age I mean we can do whatever we want right now we did not really we did not really limit this but person a age 20 age negative 20 says hello what if we did more with this right now the age is the only default parameter it has a default setting we can change this to 20 if we wanted to and we can have and we can remove this down here now by default a is a nobody fault that person is age 20 but what i'm getting at is that the optional parameters typically appear last in the list of parameters in your function you can have as many as you'd like though we can say okay character person that can be a by default uh he's going to be default age 20 what if we said x person x who's going to be age 45 can say hello person x age 45 says hello but if i remove that 45 age by default he's going to be age 20 now what if i say okay he's not person x anymore what if i just ran this without any arguments it'll use the default ones a and 20 now if i run this code person a age 20 says hello these are all the default arguments if i had another arguments sorry if i had another argument like into id that is not optional it cannot go in between these optional parameters let's check it out nope default argument missing for parameter two avoid says who that sort of thing it cannot go there it could have it would have to go before all of that because the optional parameters have to come last now that i have an id i'll actually pass that in even though we're not doing with it doing anything with in the function it's necessary because we actually required in the function i'll just pass in one and if i run the code it works just fine but it's still using the default values for person a right up there and it's using the default age 20 which we have right up there that's how it works just have some optional parameters optional settings optional arguments and they have to be in a specific position in the function list but they are very very helpful trust me you as a programmer will know when the time comes that optional parameters are an awesome thing okay thanks for watching everybody hope you enjoyed this and i'll see you in the next tutorial