Loading, please wait...

Variable Declarations

  • Outside the main program and functions

These are global variables as they can be used in the main function and any other function defined in the source file after the declaration.

  • At the start of main or other functions

These are called local variables and are declared following the opening { in the function.

Note that the declarations must come before any other statements in the

function except following a further { as given below. They can only be used in the function where they are declared.

  • Following any other { in a function, This is unusual and not normal practice. These variables can only be used before the corresponding }.
  • Both inside and outside the main or other function

In this case, two memory locations are reserved with the same name, but the local variable is always used in preference to the global variable where possible.