Exploring Functions

Whenever you need to create a large application, it is a wise decision to divide it into manageable chunks, called functions. Functions are small modules that represent tasks that can be executed independently. The code written inside a function can be invoked several times, which helps to avoid repetitive statements.

Functions help in the teamwork, debugging, and scaling of any application. Whenever you want to add more features to an application, simply add a few functions to it. When calling functions, the caller function may pass certain arguments, called actual arguments; these are then assigned to the parameters of the function. The parameters are also known as formal parameters.

The following recipes will help you understand how functions can be used to make complex applications easier and more manageable. Normally, a function can return only a single value. But in this chapter, we will learn a technique to return more than one value from a function. We will also learn how to apply recursion in functions.

In this chapter, we will cover the following recipes on strings:

  • Determining whether a number is an Armstrong number
  • Returning the maximum and minimum values of an array
  • Finding GCD using recursion
  • Converting a binary number into a hexadecimal number
  • Determining whether a number is a palindrome

As I will be using a stack structure in the recipes in this chapter, let's have a quick introduction to stack.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset