Local Variables:

                             The local variables are accessible only within the function. Using or printing these variables inside main method or outside the function will generate an error. These variables are declared inside the function and are destroyed when function ends.

Global Variables:

                               Global variables are declared outside all the functions including main. They are accessible everywhere in the same C++ file but are not accessible in other C++ files. Changing the value of a global variable in one function will change its values everywhere in the same C++ file.

Note: In functions the function header is made up of the following parts.

Return Type:

                        The function with void return type does not return any value to the place where function is called. A function may have any other return type depending on the type of variable returned from the function.

Name of the Function:

                                         Every function does have a name. The name of the function define above is main. For example , the function sqrt( ) indicates that it takes the square root of the variables placed between the round brackets.

Parameter List:

                            Any variable written between the round brackets in the function header makes up the parameter list. The parameter may have one or more variables. For example , the function sqrt( )takes only one parameter.

Function Overloading:

                                         Several functions of the same name are defined but with different signatures. This is known as function overloading.

Example 1: Write a function to find square of a number.




Example 2: Write a function to find maximum number




Previous page

-C++ loops and Statements