global declaration of x and the variable is known as a
global variable.
On the other hand, within main( ) again x is initialized to 20. Now, x is a local variable. And
the rule
is that whenever there is a conflict between a local and a global variable, it is the local variable
that gets first priority. Also note that since the global variable is available to the entire
program, it need not be passed as a parameter.
NOTE
There are two ways by which data can be made available to other parts of the program.
Either declare them as global variables or pass them as parameters or arguments.
Global variables are declared at the top of the program file. They are initialized automatically by
the system when you define them.
Do'stlaringiz bilan baham: |