Reflection: Scope Variables

I, Summary
There are two types of c variables.
     - Local
     - Global

Local variables: 
Variable whose existence is known only to the main program or functions are called local variables. Local variables are declared with in the main program or a function.

Global variables: 
Variables whose existence is known to the both main() as well as other functions are called global variables. Global variables are declared outside the main() and other functions.

Difference between Local and Global c variables:

     - Local c variable is declared in functions and blocks, while global c variables are declared outside functions and blocks.
     - Local c variables can be accessed only that function and blocks which declared it, while global c variables can be accessed within all program.
     - Local c variables when declared not initialized automatically by system you have to declared it,  while global c variables when declared initialized automatically by system. Int is initialized as 0, char as ‘’ etc.


II, Applied to solve problems

  1. Implement functions to demonstrate the differences between local and global variables

    Example1:

    Example2:


    Example3:



  2. Implement functions to demonstrate the differences between pass parameters by values and by references

Example1: 



Example 2:



Example 3:





III, Some of my thoughts

When I remember the differences between local and global variable, I can use it a suitable way. When I understand the differences between pass parameters by values and by references, I won't have some mistake about them. When I know it, my program can return more than 2 values. It makes me happy and excited.

Comments

Popular posts from this blog

Những lợi ích của việc dùng email edu cho developer

Reflection: Pointer