Introduction to Functions
Putta Hemanth Kumar
Software Developer @ Samsung Research Institute || Code and Content || IIEST || DSA || C++ || System Design || 1.5K LinkedIn
Ram, has learned and experienced what are primitive datatypes and what are user defined datatypes. Now he tries to understand what are functions in programming and why are they used.
Reading about functions from various sources, he has read this particular line from almost all sources which says that a function consists of few lines of code which are written once and used whenever needed. Now, this line has gone above his head and he’s confused that why I can’t write those lines whenever needed. This function creation and passing parameters are a huge mess and complex.
Ram was so upset and he wanted to change his mood. He was watching some reels until he received a call from one of his pals inviting him to a party. Ram, who was upset, got ready for the party right away in order to change his mood. Ram danced like his favorite hero Chiranjeevi at the celebration, which drew the attention of all the partygoers.
Ram was exhausted after the party and fell into a deep sleep. The next day, every one of his friends and relatives who had heard about Ram’s dance at the party wanted to see it again. Those friends who couldn’t make it to the party yesterday, came to Ram’s house and asked him to dance again. Ram was overjoyed at the first time that people liked his dance, but his joy faded quickly when this was repeated several times. Every time a friend or family visits him, he gets asked to dance first, and this keeps happening.
Ram, frustrated with having to dance over and over, had the idea to record his dance once, and then play the video or share the YouTube link whenever a friend or relative asks him to dance. This has given him some peace, and it benefits both of them. Ram is relieved when it’s all over and returns to his personal space, where he recalls what happened and how he handled the situation by dancing once and using the record when necessary.
领英推è
This reminded him of the?Functions?he studied but didn’t quite understand. Now that he has solved his problem with a function, like recording his dance and showing when needed. Similarly a function is written once and can be used when needed just by calling name and passing the required parameters if necessary. This way, Ram has understood the importance of Functions in programming and the mess of rewriting the lines of code repeatedly when needed.
Function Syntax:
Read about Functions in here: