Hey People..!! WWeLLcoMMe to coding tutor blog.. After a loooong time.!! So how are you doing? Me..? I'm great!!! Hope you too!!
Well.., This year , I started to write this blog by determined to end this lesson series.The reason is that this lesson series took so long to complete and also I have more fun stuff to teach you to do with your computer and mobile.. I'm hoping to add more Fun , Interesting and Interactive Stuffs to my blog. Hope you will enjoy them too!!
Alright!! Let's get started.!
What is a function? In programming , a function is like an electronic device which do things for you.
For example , If you feel hot turn on AC or fan, It'll cool you down , wanna wash some clothes? put them into the washer and turn it on, It'll wash your clothes and give you.
Want some Chilled water? put your bottle of water in to the fridge and it'll give you chilled water, warm food? put in the microwave oven... So the list goes on..! You get the idea right?
So just like those devices, functions do things for us. If you have a bunch of numbers and you want to find the maximum number out of them? You can use "MAX" function. Wanna find out the minimum number ? use the "MIN" function. Wanna sort out some messed list of things in alphabetical order? Use "SORT" function! Does the robot you programmed, going zig-zag instead of walk in a straight line? use "PID" function.(It's a code for robots ^-^)
So you can see that the "Life is easy with functions!! ".
Parts of a Function
In a c++ function, there are specific parts.
- Data Type (ReturnType)
- Function Name
- Arguments (Inputs to the function)
- Statements (Things done by the function)
- Return Value (Outputs from the function)
Steps to Writing a Function
- Understand the purpose of the function.
- Define the data that comes into the function from the caller (in the form of parameters)
- Define what data variables are needed inside the function to accomplish its goal.
- Decide on the set of steps that the program will use to accomplish this goal.
That's all about the functions. In next post let's do some exercises on functions. Bye!! :)