- Main Page
- Namespaces
- Files

- File List
- File Members

# C:/Musimathics_local/Musimat/MusimatTutorial/B0121.cpp File Reference

`#include "MusimatTutorial.h"`

Go to the source code of this file.

## Functions
| MusimatTutorialSection (B0121)
Integer | add (Integer a, Integer b)
Static Void | sumExample1 ()
Static Void | sumExample2 ()

## Function Documentation

Integer add | ( | Integer | a,
|  | Integer | b |
| ) |  |  |

Definition at line 18 of file B0121.cpp.

Referenced by sumExample1().

    00018                                   {                     //return the sum of a plus b
    00019         Integer sum = a + b;
    00020         Return(sum);
    00021 }

MusimatTutorialSection | ( | B0121 |  | ) |

Definition at line 2 of file B0121.cpp.

References sumExample1(), and sumExample2().

    00002                               {
    00003 Print("*** B.1.21 Scope of Variables ***");
    00004 /*****************************************************************************
    00005
    00006 B.1.21 Scope of Variables
    00007
    00008 A function’s formal arguments are said to have local scope because they flow into existence when
    00009 the function begins to execute and cease to exist when the function is finished.
    00010
    00011 It is also possible to declare other variables within the body of a function.
    00012 For example, the following function named add() defines a local variable named sum:
    00013 *****************************************************************************/
    00014         sumExample1(); // Step into this function to continue the tutorial
    00015         sumExample2(); // Step into this function to continue the tutorial
    00016 }

Static Void sumExample1 | ( |  | ) |

Definition at line 23 of file B0121.cpp.

References add().

Referenced by MusimatTutorialSection().

    00023                           {
    00024 /*****************************************************************************
    00025 Here is an example of calling the add() function.
    00026 *****************************************************************************/
    00027
    00028         Integer z;
    00029         z = add( 11, 13 );
    00030         Print(z);
    00031 }

Static Void sumExample2 | ( |  | ) |

Definition at line 33 of file B0121.cpp.

References x, and y.

Referenced by MusimatTutorialSection().

    00033                           {
    00034 /*****************************************************************************
    00035 Like the formal arguments a and b, the scope of variable sum is local to the function add(). They disappear
    00036 when the function exits. The only thing that persists is the expression in the Return statement,
    00037 which is passed back to the caller of the function.
    00038
    00039 Local variables can also be declared within compound statements. For example,
    00040 *****************************************************************************/
    00041
    00042         Integer x = 11;
    00043         Integer y = 9;
    00044
    00045         If (x > 10 And y < 10){
    00046                 Integer sum = x + y;
    00047                 Print(sum);
    00048         }
    00049
    00050 /*****************************************************************************
    00051 These variables disappear when the enclosing compound statement is exited.
    00052
    00053 Variables declared outside the scope of any function are called global variables. They are acces-
    00054 sible from the point they are declared until the end of the program. They are said to have global
    00055 scope.
    00056
    00057 *****************************************************************************/
    00058 }}